From 90db89a57d3052ec0d1e8a124374ad8798de6878 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Apr 2022 08:21:31 +0000 Subject: [PATCH 001/158] Auto-generated commit f4ba758ed3c368726b09e8a62bde2a6704d8bae0 --- CONTRIBUTORS | 28 + LICENSE | 481 +++++++++ NOTICE | 1 + README.md | 378 +++++++ bundle.js | 3 + bundle.js.map | 1 + package.json | 34 + stats.html | 2689 +++++++++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 3615 insertions(+) create mode 100644 CONTRIBUTORS create mode 100644 LICENSE create mode 100644 NOTICE create mode 100644 README.md create mode 100644 bundle.js create mode 100644 bundle.js.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..346c5db --- /dev/null +++ b/README.md @@ -0,0 +1,378 @@ + + +# broadcastShapes + +[![NPM version][npm-image]][npm-url] [![Build Status][test-image]][test-url] [![Coverage Status][coverage-image]][coverage-url] + +> Broadcast array shapes to a single shape. + + + +
+ +
+ + + + + + + +
+ +## Usage + +To use in Observable, + +```javascript +broadcastShapes = require( 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-shapes@umd/bundle.js' ) +``` + +To include the bundle in a webpage, + +```html + +``` + +If no recognized module system is present, access bundle contents via the global scope: + +```html + +``` + +#### broadcastShapes( shapes ) + +Broadcasts array shapes to a single shape. + +```javascript +var sh1 = [ 8, 1, 6, 1 ]; +var sh2 = [ 7, 1, 5 ]; + +var sh = broadcastShapes( [ sh1, sh2 ] ); +// returns [ 8, 7, 6, 5 ] +``` + +
+ + + + + +
+ +## Notes + +- When operating on two arrays, the function compares their shapes element-wise, beginning with the trailing (i.e., rightmost) dimension. The following are examples of compatible shapes and their corresponding broadcasted shape: + + ```text + A (4d array): 8 x 1 x 6 x 1 + B (3d array): 7 x 1 x 5 + --------------------------------- + Result (4d array): 8 x 7 x 6 x 5 + + A (2d array): 5 x 4 + B (1d array): 1 + ------------------------- + Result (2d array): 5 x 4 + + A (2d array): 5 x 4 + B (1d array): 4 + ------------------------- + Result (2d array): 5 x 4 + + A (3d array): 15 x 3 x 5 + B (3d array): 15 x 1 x 5 + ------------------------------ + Result (3d array): 15 x 3 x 5 + + A (3d array): 15 x 3 x 5 + B (2d array): 3 x 5 + ------------------------------ + Result (3d array): 15 x 3 x 5 + + A (3d array): 15 x 3 x 5 + B (2d array): 3 x 1 + ------------------------------ + Result (3d array): 15 x 3 x 5 + + A (5d array): 8 x 1 x 1 x 6 x 1 + B (4d array): 1 x 7 x 1 x 5 + C (5d array): 8 x 4 x 1 x 6 x 5 + ------------------------------------- + Result (5d array): 8 x 4 x 7 x 6 x 5 + + A (5d array): 8 x 1 x 1 x 6 x 1 + B (1d array): 0 + ------------------------------------- + Result (5d array): 8 x 1 x 1 x 6 x 0 + + A (5d array): 8 x 0 x 1 x 6 x 1 + B (2d array): 6 x 5 + ------------------------------------- + Result (5d array): 8 x 0 x 1 x 6 x 5 + + A (5d array): 8 x 1 x 1 x 6 x 1 + B (5d array): 8 x 0 x 1 x 6 x 1 + ------------------------------------- + Result (5d array): 8 x 0 x 1 x 6 x 1 + + A (3d array): 3 x 2 x 1 + B (0d array): + ----------------------------- + Result (3d array): 3 x 2 x 1 + + A (0d array): + B (3d array): 3 x 2 x 1 + ----------------------------- + Result (3d array): 3 x 2 x 1 + ``` + + As demonstrated above, arrays are not required to have the same number of dimensions in order to be broadcast compatible. Array shapes with fewer dimensions are implicitly prepended with singleton dimensions (i.e., dimensions equal to `1`). Accordingly, the following example + + ```text + A (2d array): 5 x 4 + B (1d array): 4 + ------------------------- + Result (2d array): 5 x 4 + ``` + + is equivalent to + + ```text + A (2d array): 5 x 4 + B (2d array): 1 x 4 + ------------------------- + Result (2d array): 5 x 4 + ``` + + Similarly, a zero-dimensional array is expanded (by prepending singleton dimensions) from + + ```text + A (3d array): 3 x 2 x 1 + B (0d array): + ----------------------------- + Result (3d array): 3 x 2 x 1 + ``` + + to + + ```text + A (3d array): 3 x 2 x 1 + B (3d array): 1 x 1 x 1 + ----------------------------- + Result (3d array): 3 x 2 x 1 + ``` + + Stated otherwise, every array has implicit leading dimensions of size `1`. During broadcasting, a `3 x 4` matrix is the same as a `3 x 4 x 1 x 1 x 1` multidimensional array. + +- Two respective dimensions in two shape arrays are compatible if + + 1. the dimensions are equal. + 2. one dimension is `1`. + + The two aforementioned rules apply to empty arrays or arrays that have a dimension of size `0`. For unequal dimensions, the size of the dimension which is not `1` determines the size of the output shape dimension. + + Accordingly, dimensions of size `0` must be paired with a dimension of size `0` or `1`. In such cases, by the rules above, the size of the corresponding output shape dimension is `0`. + +- The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). + + ```javascript + var sh1 = [ 3, 2 ]; + var sh2 = [ 2, 3 ]; + + var sh = broadcastShapes( [ sh1, sh2 ] ); + // returns null + ``` + + The following are examples of array shapes which are **not** compatible and do **not** broadcast: + + ```text + A (1d array): 3 + B (1d array): 4 # dimension does not match + + A (2d array): 2 x 1 + B (3d array): 8 x 4 x 3 # second dimension does not match + + A (3d array): 15 x 3 x 5 + B (2d array): 15 x 3 # singleton dimensions can only be prepended, not appended + + A (5d array): 8 x 8 x 1 x 6 x 1 + B (5d array): 8 x 0 x 1 x 6 x 1 # second dimension does not match + ``` + +
+ + + + + +
+ +## Examples + + + +```html + + + + + + + + +``` + +
+ + + + + + + + + +
+ +
+ + + + + + + + + + + + +
+ +* * * + +## Notice + +This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. + +For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. + +#### Community + +[![Chat][chat-image]][chat-url] + +--- + +## License + +See [LICENSE][stdlib-license]. + + +## Copyright + +Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. + +
+ + + + + + + + diff --git a/bundle.js b/bundle.js new file mode 100644 index 0000000..28f0df6 --- /dev/null +++ b/bundle.js @@ -0,0 +1,3 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=n()}(this,(function(){"use strict";return function(e){var n,f,t,o,r,u,i,s,l,d,h;if(f=[],0===(s=e.length))return f;if(l=(o=e[0]).length,1===s){for(d=0;dl&&(l=n[d]);for(d=0;d=0;){for(t=(r=n[0]-l+d)>=0?o[r]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;f[d]=t,d-=1}return f}})); +//# sourceMappingURL=bundle.js.map diff --git a/bundle.js.map b/bundle.js.map new file mode 100644 index 0000000..415ef56 --- /dev/null +++ b/bundle.js.map @@ -0,0 +1 @@ +{"version":3,"file":"bundle.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";uPAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,EAIR,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,EAEN,OAAOR"} \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..3b9810c --- /dev/null +++ b/package.json @@ -0,0 +1,34 @@ +{ + "name": "@stdlib/ndarray-base-broadcast-shapes", + "version": "0.0.0", + "description": "Broadcast array shapes to a single shape.", + "license": "Apache-2.0", + "main": "./bundle.js", + "homepage": "https://stdlib.io", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/ndarray-base-broadcast-shapes.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "keywords": [ + "stdlib", + "stdtypes", + "types", + "base", + "ndarray", + "broadcast", + "broadcasting", + "multidimensional", + "array", + "utilities", + "utility", + "utils", + "util" + ], + "funding": { + "type": "patreon", + "url": "https://www.patreon.com/athan" + } +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..58c78d9 --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + From 691ae6915e7ea248c13d494ccfe5026618b3005b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 30 Jun 2022 21:27:43 +0000 Subject: [PATCH 002/158] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index e004d17..71ded4c 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,8 @@ }, "dependencies": { "@stdlib/types": "^0.0.x", - "@stdlib/utils-library-manifest": "^0.0.x" + "@stdlib/utils-library-manifest": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x" }, "devDependencies": { "@stdlib/bench": "^0.0.x", @@ -84,4 +85,4 @@ "type": "patreon", "url": "https://www.patreon.com/athan" } -} +} \ No newline at end of file From 7c35fff7d1f9eed3560da330ad32a9ada0399889 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Jul 2022 11:19:36 +0000 Subject: [PATCH 003/158] Remove files --- bundle.js | 3 - bundle.js.map | 1 - stats.html | 2689 ------------------------------------------------- 3 files changed, 2693 deletions(-) delete mode 100644 bundle.js delete mode 100644 bundle.js.map delete mode 100644 stats.html diff --git a/bundle.js b/bundle.js deleted file mode 100644 index 28f0df6..0000000 --- a/bundle.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=n()}(this,(function(){"use strict";return function(e){var n,f,t,o,r,u,i,s,l,d,h;if(f=[],0===(s=e.length))return f;if(l=(o=e[0]).length,1===s){for(d=0;dl&&(l=n[d]);for(d=0;d=0;){for(t=(r=n[0]-l+d)>=0?o[r]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;f[d]=t,d-=1}return f}})); -//# sourceMappingURL=bundle.js.map diff --git a/bundle.js.map b/bundle.js.map deleted file mode 100644 index 415ef56..0000000 --- a/bundle.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"bundle.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";uPAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,EAIR,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,EAEN,OAAOR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 58c78d9..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 1489f6a22869ad0481c761cf948e4a48b84322d5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Jul 2022 11:20:23 +0000 Subject: [PATCH 004/158] 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 | 178 +- benchmark/benchmark.js | 112 - benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 152 - branches.md | 53 - browser.js | 3 + browser.js.map | 1 + docs/repl.txt | 39 - docs/types/index.d.ts | 177 -- docs/types/test.ts | 45 - examples/c/Makefile | 146 - examples/c/example.c | 50 - examples/index.js | 54 - .../stdlib/ndarray/base/broadcast_shapes.h | 40 - index.js | 3 + index.js.map | 1 + lib/index.js | 45 - lib/main.js | 256 -- manifest.json | 38 - package.json | 58 +- src/main.c | 118 - stats_browser.html | 2689 +++++++++++++++++ stats_node.html | 2689 +++++++++++++++++ test/test.js | 230 -- 47 files changed, 5424 insertions(+), 4748 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.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 branches.md create mode 100644 browser.js create mode 100644 browser.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/index.d.ts delete mode 100644 docs/types/test.ts delete mode 100644 examples/c/Makefile delete mode 100644 examples/c/example.c delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/broadcast_shapes.h create mode 100644 index.js create mode 100644 index.js.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 manifest.json delete mode 100644 src/main.c create mode 100644 stats_browser.html create mode 100644 stats_node.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 b6211ec..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-06-30T21:27:08.779Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 7f004ad..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 8a49110..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 +``` + +If no recognized module system is present, access bundle contents via the global scope: + +```html + ``` #### broadcastShapes( shapes ) @@ -232,9 +240,14 @@ var sh = broadcastShapes( [ sh1, sh2 ] ); -```javascript -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); +```html + + + + + + + + ```
@@ -275,131 +293,7 @@ for ( i = 0; i < shapes.length; i++ ) { -* * * - -
- -## C APIs - - - -
- -
- - - - - -
- -### Usage - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -``` - -#### stdlib_ndarray_broadcast_shapes( M, \*\*shapes, \*ndims, \*out ) - -Broadcasts array shapes to a single shape. - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -int64_t N1 = 4; -int64_t sh1[] = { 8, 1, 6, 1 }; - -int64_t N2 = 3; -int64_t sh2[] = { 7, 1, 5 }; - -int64_t ndims[] = { N1, N2 }; -int64_t *shapes[] = { sh1, sh2 }; - -int64_t out[] = { 0, 0, 0, 0 }; -int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -if ( status != 0 ) { - // Handle error... -} -``` - -The function accepts the following arguments: - -- **M**: `[in] int64_t` number of shape arrays. -- **shapes**: `[in] int64_t**` array of shape arrays (dimensions). -- **ndims**: `[in] int64_t*` number of dimensions for each respective shape array. -- **out**: `[out] int64_t*` output shape array. - -```c -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ); -``` - -If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). - -
- - - - - -
- -### Notes - -- Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. - -
- - - - - -
- -### Examples - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main() { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} -``` - -
- - - -
- diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index fa610dc..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,112 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pkg = require( './../package.json' ).name; -var broadcastShapes = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::two_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ] ], - [ [ 3, 2 ], [ 3, 1 ] ], - [ [ 1, 1 ], [ 2, 2 ] ], - [ [ 1 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::three_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::four_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ], [ 8, 1, 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ], [ 1, 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ], [ 1, 1, 2, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ], [ 1 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ], [ 5, 1, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/c/Makefile b/benchmark/c/Makefile deleted file mode 100644 index 5dc545c..0000000 --- a/benchmark/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := benchmark.out - - -# RULES # - -#/ -# Compiles C source files. -# -# @param {string} SOURCE_FILES - list of C source files -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lpthread -lblas`) -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [C_COMPILER] - C compiler -# @param {string} [CFLAGS] - C compiler flags -# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} SOURCE_FILES - list of C source files -# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {(string|void)} LIBRARIES - list of libraries (e.g., `-lpthread -lblas`) -# @param {(string|void)} LIBPATH - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} CC - C compiler -# @param {string} CFLAGS - C compiler flags -# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled benchmarks. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/benchmark/c/benchmark.c b/benchmark/c/benchmark.c deleted file mode 100644 index be62cd5..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,152 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/** -* Benchmark `broadcast_shapes`. -*/ -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "broadcast-shapes" -#define ITERATIONS 1000000 -#define REPEATS 3 - -/** -* Prints the TAP version. -*/ -void print_version() { - printf( "TAP version 13\n" ); -} - -/** -* Prints the TAP summary. -* -* @param total total number of tests -* @param passing total number of passing tests -*/ -void print_summary( int total, int passing ) { - printf( "#\n" ); - printf( "1..%d\n", total ); // TAP plan - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); -} - -/** -* Prints benchmarks results. -* -* @param elapsed elapsed time in seconds -*/ -void print_results( double elapsed ) { - double rate = (double)ITERATIONS / elapsed; - printf( " ---\n" ); - printf( " iterations: %d\n", ITERATIONS ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", rate ); - printf( " ...\n" ); -} - -/** -* Returns a clock time. -* -* @return clock time -*/ -double tic() { - struct timeval now; - gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; -} - -/** -* Generates a random double on the interval [0,1]. -* -* @return random double -*/ -double rand_double() { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark() { - double elapsed; - int8_t status; - double t; - int i; - - int64_t sh1[] = { 8, 1, 6, 1 }; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { 4, 3 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( out[ 0 ] != 8 ) { - printf( "unexpected result\n" ); - } - if ( out[ 1 ] != 7 ) { - printf( "unexpected result\n" ); - } - if ( out[ 2 ] != 6 ) { - printf( "unexpected result\n" ); - } - if ( out[ 3 ] != 5 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Main execution sequence. -*/ -int main( void ) { - double elapsed; - int i; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - for ( i = 0; i < REPEATS; i++ ) { - printf( "# c::native::%s::two_arrays\n", NAME ); - elapsed = benchmark(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", i+1 ); - } - print_summary( REPEATS, REPEATS ); -} diff --git a/branches.md b/branches.md deleted file mode 100644 index 20fbab5..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes" -click B href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/main" -click C href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production" -click D href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm \ No newline at end of file diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..3c259e1 --- /dev/null +++ b/browser.js @@ -0,0 +1,3 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map new file mode 100644 index 0000000..1fb93c0 --- /dev/null +++ b/browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"browser.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,EAIR,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,EAEN,OAAOR"} \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f1d92f6..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,39 +0,0 @@ - -{{alias}}( shapes ) - Broadcasts array shapes to a single shape. - - Two respective dimensions in two shape arrays are compatible if - - 1. the dimensions are equal. - 2. one dimension is `1`. - - The function returns `null` if provided incompatible shapes (i.e., shapes - which cannot be broadcast with one another). - - Parameters - ---------- - shapes: Array - Array of shape arrays. - - Returns - ------- - out: Array|null - Broadcast shape. - - Examples - -------- - // Compatible shapes: - > var sh1 = [ 8, 1, 6, 1 ]; - > var sh2 = [ 7, 1, 5 ]; - > var sh = {{alias}}( [ sh1, sh2 ] ) - [ 8, 7, 6, 5 ] - - // Incompatible shapes: - > sh1 = [ 3, 2 ]; - > sh1 = [ 2, 3 ]; - > sh = {{alias}}( [ sh1, sh2 ] ) - null - - See Also - -------- - diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts deleted file mode 100644 index f46767d..0000000 --- a/docs/types/index.d.ts +++ /dev/null @@ -1,177 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ArrayLike } from '@stdlib/types/array'; - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param shapes - array shapes -* @returns broadcast shape -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -declare function broadcastShapes( shapes: ArrayLike> ): ArrayLike; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = broadcastShapes; diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 2886539..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 broadcastShapes = require( './index' ); - - -// TESTS // - -// The function returns an array of numbers... -{ - broadcastShapes( [ [ 1, 2 ], [ 2, 2 ] ] ); // $ExpectType ArrayLike -} - -// The compiler throws an error if the function is not provided an array-like object containing array-like objects containing numbers... -{ - broadcastShapes( '5' ); // $ExpectError - broadcastShapes( 5 ); // $ExpectError - broadcastShapes( true ); // $ExpectError - broadcastShapes( false ); // $ExpectError - broadcastShapes( null ); // $ExpectError - broadcastShapes( {} ); // $ExpectError - broadcastShapes( [ '5' ] ); // $ExpectError - broadcastShapes( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - broadcastShapes(); // $ExpectError - broadcastShapes( [ [ 1, 2, 3 ] ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/c/Makefile b/examples/c/Makefile deleted file mode 100644 index 70c91f4..0000000 --- a/examples/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := example.out - - -# RULES # - -#/ -# Compiles source files. -# -# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) -# @param {string} [CFLAGS] - C compiler options -# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) -# @param {string} [SOURCE_FILES] - list of source files -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} CC - C compiler (e.g., `gcc`) -# @param {string} CFLAGS - C compiler options -# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) -# @param {string} SOURCE_FILES - list of source files -# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) -# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled examples. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/examples/c/example.c b/examples/c/example.c deleted file mode 100644 index fae2252..0000000 --- a/examples/c/example.c +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main() { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 28811f9..0000000 --- a/examples/index.js +++ /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. -*/ - -'use strict'; - -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( './../lib' ); - -var shapes; -var out; -var sh; -var i; -var j; - -function shape2string( shape ) { - return lpad( shape.join( ' x ' ), 20, ' ' ); -} - -shapes = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] -]; - -for ( i = 0; i < shapes.length; i++ ) { - sh = shapes[ i ]; - for ( j = 0; j < sh.length; j++ ) { - console.log( shape2string( sh[ j ] ) ); - } - console.log( lpad( '', 20, '-' ) ); - - out = broadcastShapes( sh ); - console.log( shape2string( out )+'\n' ); -} diff --git a/include/stdlib/ndarray/base/broadcast_shapes.h b/include/stdlib/ndarray/base/broadcast_shapes.h deleted file mode 100644 index e23dce1..0000000 --- a/include/stdlib/ndarray/base/broadcast_shapes.h +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#ifndef STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H -#define STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H - -#include - -/* -* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. -*/ -#ifdef __cplusplus -extern "C" { -#endif - -/** -* Broadcasts array shapes to a single shape. -*/ -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H diff --git a/index.js b/index.js new file mode 100644 index 0000000..635432d --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map new file mode 100644 index 0000000..b2b182b --- /dev/null +++ b/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,EAIR,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,EAEN,OAAOR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 0c9817e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Broadcast array shapes to a single shape. -* -* @module @stdlib/ndarray-base-broadcast-shapes -* -* @example -* var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); -* -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -*/ - -// 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 8558e60..0000000 --- a/lib/main.js +++ /dev/null @@ -1,256 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param {Array} shapes - array of shape arrays -* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`) -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [ 8, 0, 1, 6, 1 ], -* [ 8, 8, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -function broadcastShapes( shapes ) { - var ndims; - var out; - var dim; - var sh; - var n1; - var n2; - var d; - var M; - var N; - var i; - var j; - - M = shapes.length; - out = []; - if ( M === 0 ) { - return out; - } - sh = shapes[ 0 ]; - N = sh.length; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M === 1 ) { - // Need to manually copy to output shape, as shapes could be array-like objects... - for ( i = 0; i < N; i++ ) { - out.push( sh[ i ] ); - } - return out; - } - // Determine the maximum dimensionality... - ndims = [ N ]; - for ( i = 1; i < M; i++ ) { - ndims.push( shapes[ i ].length ); - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Initialize the output array... - for ( i = 0; i < N; i++ ) { - out.push( 0 ); - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim === 1 ) { - dim = d; - continue; - } - if ( d === 1 || dim === d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return null; - } - out[ i ] = dim; - i -= 1; - } - return out; -} - - -// EXPORTS // - -module.exports = broadcastShapes; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 890a937..0000000 --- a/manifest.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "options": {}, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [] - } - ] -} diff --git a/package.json b/package.json index 71ded4c..8503511 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,7 @@ "version": "0.0.8", "description": "Broadcast array shapes to a single shape.", "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", - "include": "./include", - "lib": "./lib", - "src": "./src", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "main": "./browser.js", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,33 +12,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/types": "^0.0.x", - "@stdlib/utils-library-manifest": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x" - }, - "devDependencies": { - "@stdlib/bench": "^0.0.x", - "@stdlib/string-left-pad": "^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", "stdtypes", @@ -80,9 +27,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" } -} \ No newline at end of file +} diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 35a3654..0000000 --- a/src/main.c +++ /dev/null @@ -1,118 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). -* -* - Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. -* -* @param M number of array shapes -* @param shapes pointer to an array containing shape arrays -* @param ndims array containing the number of dimensions for (i.e., length of) each respective shape array -* @param out pointer to output array -* @return status -* -* @example -* #include "stdlib/ndarray/base/broadcast_shapes.h" -* #include -* -* int64_t N1 = 4; -* int64_t sh1[] = { 8, 1, 6, 1 }; -* -* int64_t N2 = 3; -* int64_t sh2[] = { 7, 1, 5 }; -* -* int64_t ndims[] = { N1, N2 }; -* int64_t *shapes[] = { sh1, sh2 }; -* -* int64_t out[] = { 0, 0, 0, 0 }; -* int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -*/ -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ) { - int64_t dim; - int64_t *sh; - int64_t n1; - int64_t n2; - int64_t d; - int64_t N; - int64_t i; - int64_t j; - - if ( M == 0 ) { - return 0; - } - sh = shapes[ 0 ]; - N = ndims[ 0 ]; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M == 1 ) { - for ( i = 0; i < N; i++ ) { - out[ i ] = sh[ i ]; - } - return 0; - } - // Determine the maximum dimensionality... - for ( i = 1; i < M; i++ ) { - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim == 1 ) { - dim = d; - continue; - } - if ( d == 1 || dim == d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return -1; - } - out[ i ] = dim; - i -= 1; - } - return 0; -} diff --git a/stats_browser.html b/stats_browser.html new file mode 100644 index 0000000..40aa7f4 --- /dev/null +++ b/stats_browser.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/stats_node.html b/stats_node.html new file mode 100644 index 0000000..11cd0c4 --- /dev/null +++ b/stats_node.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 63f703c..0000000 --- a/test/test.js +++ /dev/null @@ -1,230 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var broadcastShapes = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastShapes, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] - ]; - - expected = [ - [ 1, 2 ], - [ 3, 4 ], - [ 5, 6, 7 ], - [ 3, 3 ], - [ 3 ], - [ 3, 2 ], - [ 2, 3 ], - [ 1, 2 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty dims)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 0 ], [ 0, 0 ] ], - [ [ 0, 1 ], [ 0, 0 ] ], - [ [ 1, 0 ], [ 0, 1 ] ], - [ [ 1, 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 1, 0 ] ], - [ [ 1, 1 ], [ 0, 1 ] ], - [ [ 0 ], [ 0, 0 ] ], - [ [ 0 ], [ 0, 1 ] ], - [ [ 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 0 ] ], - [ [ 1 ], [ 0, 1 ] ], - [ [ 1 ], [ 1, 0 ] ], - [ [ 1 ], [ 8, 0 ] ], - [ [ 8, 1, 6, 1 ], [ 0, 1, 5 ] ], - [ [ 8, 0, 6, 1 ], [ 1, 5 ] ] - ]; - - expected = [ - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 1, 0 ], - [ 8, 0 ], - [ 8, 0, 6, 5 ], - [ 8, 0, 6, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (no shapes)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [] - ]; - - expected = [ - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty shapes (i.e., zero-dimensional array broadcasting))', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [] ], - [ [], [] ], - [ [], [], [] ], - [ [], [ 0 ] ], - [ [ 0 ], [] ], - [ [], [ 0, 0 ] ], - [ [ 0, 0 ], [] ], - [ [], [ 1, 0 ] ], - [ [], [ 0, 1 ] ], - [ [], [ 3, 3 ] ], - [ [], [ 3, 3 ], [] ] - ]; - - expected = [ - [], - [], - [], - [ 0 ], - [ 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 3, 3 ], - [ 3, 3 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (single shape)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 7 ] ], - [ [ 1, 1 ] ], - [ [ 5, 6, 1 ] ] - ]; - - expected = [ - [ 7 ], - [ 1, 1 ], - [ 5, 6, 1 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function returns `null` if provided incompatible shapes', function test( t ) { - var actual; - var values; - var i; - - values = [ - [ [ 3 ], [ 4 ] ], - [ [ 2, 3 ], [ 2 ] ], - [ [ 3 ], [ 3 ], [ 4 ] ], - [ [ 1, 3, 4 ], [ 2, 3, 3 ] ], - [ [ 1, 2 ], [ 3, 1 ], [ 3, 2 ], [ 10, 5 ] ], - [ [ 2 ], [ 2, 3 ] ], - [ [ 2 ], [ 2 ], [ 2 ], [ 2 ], [ 3 ], [ 3 ], [ 3 ], [ 3 ] ], - [ [ 9, 0, 9 ], [ 0, 9, 0 ] ], - [ [ 9, 9, 9 ], [ 0, 9, 9 ] ], - [ [ 9, 0, 9 ], [ 9, 9, 9 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 0 ] ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.strictEqual( actual, null, 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); From 80c4b92cccd2dff23af6d1206cfb6920493acd9b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Jul 2022 17:20:25 +0000 Subject: [PATCH 005/158] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index e004d17..71ded4c 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,8 @@ }, "dependencies": { "@stdlib/types": "^0.0.x", - "@stdlib/utils-library-manifest": "^0.0.x" + "@stdlib/utils-library-manifest": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x" }, "devDependencies": { "@stdlib/bench": "^0.0.x", @@ -84,4 +85,4 @@ "type": "patreon", "url": "https://www.patreon.com/athan" } -} +} \ No newline at end of file From c624a88f93e423f289b10c0d21f915f901084740 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 2 Jul 2022 02:00:21 +0000 Subject: [PATCH 006/158] Remove files --- browser.js | 3 - browser.js.map | 1 - index.js | 3 - index.js.map | 1 - stats_browser.html | 2689 -------------------------------------------- stats_node.html | 2689 -------------------------------------------- 6 files changed, 5386 deletions(-) delete mode 100644 browser.js delete mode 100644 browser.js.map delete mode 100644 index.js delete mode 100644 index.js.map delete mode 100644 stats_browser.html delete mode 100644 stats_node.html diff --git a/browser.js b/browser.js deleted file mode 100644 index 3c259e1..0000000 --- a/browser.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); -//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map deleted file mode 100644 index 1fb93c0..0000000 --- a/browser.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"browser.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,EAIR,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,EAEN,OAAOR"} \ No newline at end of file diff --git a/index.js b/index.js deleted file mode 100644 index 635432d..0000000 --- a/index.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); -//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map deleted file mode 100644 index b2b182b..0000000 --- a/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,EAIR,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,EAEN,OAAOR"} \ No newline at end of file diff --git a/stats_browser.html b/stats_browser.html deleted file mode 100644 index 40aa7f4..0000000 --- a/stats_browser.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - diff --git a/stats_node.html b/stats_node.html deleted file mode 100644 index 11cd0c4..0000000 --- a/stats_node.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From cc35fa91780c9c4f29bd1d5cebeed66936cd6435 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 2 Jul 2022 02:01:00 +0000 Subject: [PATCH 007/158] 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 | 178 +- benchmark/benchmark.js | 112 - benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 152 - branches.md | 53 - browser.js | 3 + browser.js.map | 1 + docs/repl.txt | 39 - docs/types/index.d.ts | 177 -- docs/types/test.ts | 45 - examples/c/Makefile | 146 - examples/c/example.c | 50 - examples/index.js | 54 - .../stdlib/ndarray/base/broadcast_shapes.h | 40 - index.js | 3 + index.js.map | 1 + lib/index.js | 45 - lib/main.js | 256 -- manifest.json | 38 - package.json | 58 +- src/main.c | 118 - stats_browser.html | 2689 +++++++++++++++++ stats_node.html | 2689 +++++++++++++++++ test/test.js | 230 -- 47 files changed, 5424 insertions(+), 4748 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.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 branches.md create mode 100644 browser.js create mode 100644 browser.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/index.d.ts delete mode 100644 docs/types/test.ts delete mode 100644 examples/c/Makefile delete mode 100644 examples/c/example.c delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/broadcast_shapes.h create mode 100644 index.js create mode 100644 index.js.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 manifest.json delete mode 100644 src/main.c create mode 100644 stats_browser.html create mode 100644 stats_node.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 6cfa9aa..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-07-01T00:46:57.188Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 7f004ad..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 8a49110..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 +``` + +If no recognized module system is present, access bundle contents via the global scope: + +```html + ``` #### broadcastShapes( shapes ) @@ -232,9 +240,14 @@ var sh = broadcastShapes( [ sh1, sh2 ] ); -```javascript -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); +```html + + + + + + + + ```
@@ -275,131 +293,7 @@ for ( i = 0; i < shapes.length; i++ ) { -* * * - -
- -## C APIs - - - -
- -
- - - - - -
- -### Usage - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -``` - -#### stdlib_ndarray_broadcast_shapes( M, \*\*shapes, \*ndims, \*out ) - -Broadcasts array shapes to a single shape. - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -int64_t N1 = 4; -int64_t sh1[] = { 8, 1, 6, 1 }; - -int64_t N2 = 3; -int64_t sh2[] = { 7, 1, 5 }; - -int64_t ndims[] = { N1, N2 }; -int64_t *shapes[] = { sh1, sh2 }; - -int64_t out[] = { 0, 0, 0, 0 }; -int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -if ( status != 0 ) { - // Handle error... -} -``` - -The function accepts the following arguments: - -- **M**: `[in] int64_t` number of shape arrays. -- **shapes**: `[in] int64_t**` array of shape arrays (dimensions). -- **ndims**: `[in] int64_t*` number of dimensions for each respective shape array. -- **out**: `[out] int64_t*` output shape array. - -```c -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ); -``` - -If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). - -
- - - - - -
- -### Notes - -- Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. - -
- - - - - -
- -### Examples - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main() { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} -``` - -
- - - -
- diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index fa610dc..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,112 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pkg = require( './../package.json' ).name; -var broadcastShapes = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::two_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ] ], - [ [ 3, 2 ], [ 3, 1 ] ], - [ [ 1, 1 ], [ 2, 2 ] ], - [ [ 1 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::three_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::four_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ], [ 8, 1, 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ], [ 1, 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ], [ 1, 1, 2, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ], [ 1 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ], [ 5, 1, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/c/Makefile b/benchmark/c/Makefile deleted file mode 100644 index 5dc545c..0000000 --- a/benchmark/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := benchmark.out - - -# RULES # - -#/ -# Compiles C source files. -# -# @param {string} SOURCE_FILES - list of C source files -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lpthread -lblas`) -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [C_COMPILER] - C compiler -# @param {string} [CFLAGS] - C compiler flags -# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} SOURCE_FILES - list of C source files -# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {(string|void)} LIBRARIES - list of libraries (e.g., `-lpthread -lblas`) -# @param {(string|void)} LIBPATH - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} CC - C compiler -# @param {string} CFLAGS - C compiler flags -# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled benchmarks. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/benchmark/c/benchmark.c b/benchmark/c/benchmark.c deleted file mode 100644 index be62cd5..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,152 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/** -* Benchmark `broadcast_shapes`. -*/ -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "broadcast-shapes" -#define ITERATIONS 1000000 -#define REPEATS 3 - -/** -* Prints the TAP version. -*/ -void print_version() { - printf( "TAP version 13\n" ); -} - -/** -* Prints the TAP summary. -* -* @param total total number of tests -* @param passing total number of passing tests -*/ -void print_summary( int total, int passing ) { - printf( "#\n" ); - printf( "1..%d\n", total ); // TAP plan - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); -} - -/** -* Prints benchmarks results. -* -* @param elapsed elapsed time in seconds -*/ -void print_results( double elapsed ) { - double rate = (double)ITERATIONS / elapsed; - printf( " ---\n" ); - printf( " iterations: %d\n", ITERATIONS ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", rate ); - printf( " ...\n" ); -} - -/** -* Returns a clock time. -* -* @return clock time -*/ -double tic() { - struct timeval now; - gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; -} - -/** -* Generates a random double on the interval [0,1]. -* -* @return random double -*/ -double rand_double() { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark() { - double elapsed; - int8_t status; - double t; - int i; - - int64_t sh1[] = { 8, 1, 6, 1 }; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { 4, 3 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( out[ 0 ] != 8 ) { - printf( "unexpected result\n" ); - } - if ( out[ 1 ] != 7 ) { - printf( "unexpected result\n" ); - } - if ( out[ 2 ] != 6 ) { - printf( "unexpected result\n" ); - } - if ( out[ 3 ] != 5 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Main execution sequence. -*/ -int main( void ) { - double elapsed; - int i; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - for ( i = 0; i < REPEATS; i++ ) { - printf( "# c::native::%s::two_arrays\n", NAME ); - elapsed = benchmark(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", i+1 ); - } - print_summary( REPEATS, REPEATS ); -} diff --git a/branches.md b/branches.md deleted file mode 100644 index 20fbab5..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes" -click B href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/main" -click C href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production" -click D href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm \ No newline at end of file diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..3c259e1 --- /dev/null +++ b/browser.js @@ -0,0 +1,3 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map new file mode 100644 index 0000000..1fb93c0 --- /dev/null +++ b/browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"browser.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,EAIR,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,EAEN,OAAOR"} \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f1d92f6..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,39 +0,0 @@ - -{{alias}}( shapes ) - Broadcasts array shapes to a single shape. - - Two respective dimensions in two shape arrays are compatible if - - 1. the dimensions are equal. - 2. one dimension is `1`. - - The function returns `null` if provided incompatible shapes (i.e., shapes - which cannot be broadcast with one another). - - Parameters - ---------- - shapes: Array - Array of shape arrays. - - Returns - ------- - out: Array|null - Broadcast shape. - - Examples - -------- - // Compatible shapes: - > var sh1 = [ 8, 1, 6, 1 ]; - > var sh2 = [ 7, 1, 5 ]; - > var sh = {{alias}}( [ sh1, sh2 ] ) - [ 8, 7, 6, 5 ] - - // Incompatible shapes: - > sh1 = [ 3, 2 ]; - > sh1 = [ 2, 3 ]; - > sh = {{alias}}( [ sh1, sh2 ] ) - null - - See Also - -------- - diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts deleted file mode 100644 index f46767d..0000000 --- a/docs/types/index.d.ts +++ /dev/null @@ -1,177 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ArrayLike } from '@stdlib/types/array'; - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param shapes - array shapes -* @returns broadcast shape -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -declare function broadcastShapes( shapes: ArrayLike> ): ArrayLike; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = broadcastShapes; diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 2886539..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 broadcastShapes = require( './index' ); - - -// TESTS // - -// The function returns an array of numbers... -{ - broadcastShapes( [ [ 1, 2 ], [ 2, 2 ] ] ); // $ExpectType ArrayLike -} - -// The compiler throws an error if the function is not provided an array-like object containing array-like objects containing numbers... -{ - broadcastShapes( '5' ); // $ExpectError - broadcastShapes( 5 ); // $ExpectError - broadcastShapes( true ); // $ExpectError - broadcastShapes( false ); // $ExpectError - broadcastShapes( null ); // $ExpectError - broadcastShapes( {} ); // $ExpectError - broadcastShapes( [ '5' ] ); // $ExpectError - broadcastShapes( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - broadcastShapes(); // $ExpectError - broadcastShapes( [ [ 1, 2, 3 ] ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/c/Makefile b/examples/c/Makefile deleted file mode 100644 index 70c91f4..0000000 --- a/examples/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := example.out - - -# RULES # - -#/ -# Compiles source files. -# -# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) -# @param {string} [CFLAGS] - C compiler options -# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) -# @param {string} [SOURCE_FILES] - list of source files -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} CC - C compiler (e.g., `gcc`) -# @param {string} CFLAGS - C compiler options -# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) -# @param {string} SOURCE_FILES - list of source files -# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) -# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled examples. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/examples/c/example.c b/examples/c/example.c deleted file mode 100644 index fae2252..0000000 --- a/examples/c/example.c +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main() { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 28811f9..0000000 --- a/examples/index.js +++ /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. -*/ - -'use strict'; - -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( './../lib' ); - -var shapes; -var out; -var sh; -var i; -var j; - -function shape2string( shape ) { - return lpad( shape.join( ' x ' ), 20, ' ' ); -} - -shapes = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] -]; - -for ( i = 0; i < shapes.length; i++ ) { - sh = shapes[ i ]; - for ( j = 0; j < sh.length; j++ ) { - console.log( shape2string( sh[ j ] ) ); - } - console.log( lpad( '', 20, '-' ) ); - - out = broadcastShapes( sh ); - console.log( shape2string( out )+'\n' ); -} diff --git a/include/stdlib/ndarray/base/broadcast_shapes.h b/include/stdlib/ndarray/base/broadcast_shapes.h deleted file mode 100644 index e23dce1..0000000 --- a/include/stdlib/ndarray/base/broadcast_shapes.h +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#ifndef STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H -#define STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H - -#include - -/* -* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. -*/ -#ifdef __cplusplus -extern "C" { -#endif - -/** -* Broadcasts array shapes to a single shape. -*/ -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H diff --git a/index.js b/index.js new file mode 100644 index 0000000..635432d --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map new file mode 100644 index 0000000..b2b182b --- /dev/null +++ b/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,EAIR,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,EAEN,OAAOR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 0c9817e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Broadcast array shapes to a single shape. -* -* @module @stdlib/ndarray-base-broadcast-shapes -* -* @example -* var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); -* -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -*/ - -// 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 8558e60..0000000 --- a/lib/main.js +++ /dev/null @@ -1,256 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param {Array} shapes - array of shape arrays -* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`) -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [ 8, 0, 1, 6, 1 ], -* [ 8, 8, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -function broadcastShapes( shapes ) { - var ndims; - var out; - var dim; - var sh; - var n1; - var n2; - var d; - var M; - var N; - var i; - var j; - - M = shapes.length; - out = []; - if ( M === 0 ) { - return out; - } - sh = shapes[ 0 ]; - N = sh.length; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M === 1 ) { - // Need to manually copy to output shape, as shapes could be array-like objects... - for ( i = 0; i < N; i++ ) { - out.push( sh[ i ] ); - } - return out; - } - // Determine the maximum dimensionality... - ndims = [ N ]; - for ( i = 1; i < M; i++ ) { - ndims.push( shapes[ i ].length ); - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Initialize the output array... - for ( i = 0; i < N; i++ ) { - out.push( 0 ); - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim === 1 ) { - dim = d; - continue; - } - if ( d === 1 || dim === d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return null; - } - out[ i ] = dim; - i -= 1; - } - return out; -} - - -// EXPORTS // - -module.exports = broadcastShapes; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 890a937..0000000 --- a/manifest.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "options": {}, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [] - } - ] -} diff --git a/package.json b/package.json index 71ded4c..8503511 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,7 @@ "version": "0.0.8", "description": "Broadcast array shapes to a single shape.", "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", - "include": "./include", - "lib": "./lib", - "src": "./src", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "main": "./browser.js", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,33 +12,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/types": "^0.0.x", - "@stdlib/utils-library-manifest": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x" - }, - "devDependencies": { - "@stdlib/bench": "^0.0.x", - "@stdlib/string-left-pad": "^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", "stdtypes", @@ -80,9 +27,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" } -} \ No newline at end of file +} diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 35a3654..0000000 --- a/src/main.c +++ /dev/null @@ -1,118 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). -* -* - Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. -* -* @param M number of array shapes -* @param shapes pointer to an array containing shape arrays -* @param ndims array containing the number of dimensions for (i.e., length of) each respective shape array -* @param out pointer to output array -* @return status -* -* @example -* #include "stdlib/ndarray/base/broadcast_shapes.h" -* #include -* -* int64_t N1 = 4; -* int64_t sh1[] = { 8, 1, 6, 1 }; -* -* int64_t N2 = 3; -* int64_t sh2[] = { 7, 1, 5 }; -* -* int64_t ndims[] = { N1, N2 }; -* int64_t *shapes[] = { sh1, sh2 }; -* -* int64_t out[] = { 0, 0, 0, 0 }; -* int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -*/ -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ) { - int64_t dim; - int64_t *sh; - int64_t n1; - int64_t n2; - int64_t d; - int64_t N; - int64_t i; - int64_t j; - - if ( M == 0 ) { - return 0; - } - sh = shapes[ 0 ]; - N = ndims[ 0 ]; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M == 1 ) { - for ( i = 0; i < N; i++ ) { - out[ i ] = sh[ i ]; - } - return 0; - } - // Determine the maximum dimensionality... - for ( i = 1; i < M; i++ ) { - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim == 1 ) { - dim = d; - continue; - } - if ( d == 1 || dim == d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return -1; - } - out[ i ] = dim; - i -= 1; - } - return 0; -} diff --git a/stats_browser.html b/stats_browser.html new file mode 100644 index 0000000..1438116 --- /dev/null +++ b/stats_browser.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/stats_node.html b/stats_node.html new file mode 100644 index 0000000..891fd19 --- /dev/null +++ b/stats_node.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 63f703c..0000000 --- a/test/test.js +++ /dev/null @@ -1,230 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var broadcastShapes = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastShapes, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] - ]; - - expected = [ - [ 1, 2 ], - [ 3, 4 ], - [ 5, 6, 7 ], - [ 3, 3 ], - [ 3 ], - [ 3, 2 ], - [ 2, 3 ], - [ 1, 2 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty dims)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 0 ], [ 0, 0 ] ], - [ [ 0, 1 ], [ 0, 0 ] ], - [ [ 1, 0 ], [ 0, 1 ] ], - [ [ 1, 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 1, 0 ] ], - [ [ 1, 1 ], [ 0, 1 ] ], - [ [ 0 ], [ 0, 0 ] ], - [ [ 0 ], [ 0, 1 ] ], - [ [ 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 0 ] ], - [ [ 1 ], [ 0, 1 ] ], - [ [ 1 ], [ 1, 0 ] ], - [ [ 1 ], [ 8, 0 ] ], - [ [ 8, 1, 6, 1 ], [ 0, 1, 5 ] ], - [ [ 8, 0, 6, 1 ], [ 1, 5 ] ] - ]; - - expected = [ - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 1, 0 ], - [ 8, 0 ], - [ 8, 0, 6, 5 ], - [ 8, 0, 6, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (no shapes)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [] - ]; - - expected = [ - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty shapes (i.e., zero-dimensional array broadcasting))', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [] ], - [ [], [] ], - [ [], [], [] ], - [ [], [ 0 ] ], - [ [ 0 ], [] ], - [ [], [ 0, 0 ] ], - [ [ 0, 0 ], [] ], - [ [], [ 1, 0 ] ], - [ [], [ 0, 1 ] ], - [ [], [ 3, 3 ] ], - [ [], [ 3, 3 ], [] ] - ]; - - expected = [ - [], - [], - [], - [ 0 ], - [ 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 3, 3 ], - [ 3, 3 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (single shape)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 7 ] ], - [ [ 1, 1 ] ], - [ [ 5, 6, 1 ] ] - ]; - - expected = [ - [ 7 ], - [ 1, 1 ], - [ 5, 6, 1 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function returns `null` if provided incompatible shapes', function test( t ) { - var actual; - var values; - var i; - - values = [ - [ [ 3 ], [ 4 ] ], - [ [ 2, 3 ], [ 2 ] ], - [ [ 3 ], [ 3 ], [ 4 ] ], - [ [ 1, 3, 4 ], [ 2, 3, 3 ] ], - [ [ 1, 2 ], [ 3, 1 ], [ 3, 2 ], [ 10, 5 ] ], - [ [ 2 ], [ 2, 3 ] ], - [ [ 2 ], [ 2 ], [ 2 ], [ 2 ], [ 3 ], [ 3 ], [ 3 ], [ 3 ] ], - [ [ 9, 0, 9 ], [ 0, 9, 0 ] ], - [ [ 9, 9, 9 ], [ 0, 9, 9 ] ], - [ [ 9, 0, 9 ], [ 9, 9, 9 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 0 ] ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.strictEqual( actual, null, 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); From 167f47b8253ba85a56d004d917a30f05dc2daa3c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 6 Jul 2022 18:34:08 +0000 Subject: [PATCH 008/158] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index e004d17..71ded4c 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,8 @@ }, "dependencies": { "@stdlib/types": "^0.0.x", - "@stdlib/utils-library-manifest": "^0.0.x" + "@stdlib/utils-library-manifest": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x" }, "devDependencies": { "@stdlib/bench": "^0.0.x", @@ -84,4 +85,4 @@ "type": "patreon", "url": "https://www.patreon.com/athan" } -} +} \ No newline at end of file From 8085454b1257edf1de7506c13bcec2140e2d669e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 6 Jul 2022 18:59:04 +0000 Subject: [PATCH 009/158] Remove files --- browser.js | 3 - browser.js.map | 1 - index.js | 3 - index.js.map | 1 - stats_browser.html | 2689 -------------------------------------------- stats_node.html | 2689 -------------------------------------------- 6 files changed, 5386 deletions(-) delete mode 100644 browser.js delete mode 100644 browser.js.map delete mode 100644 index.js delete mode 100644 index.js.map delete mode 100644 stats_browser.html delete mode 100644 stats_node.html diff --git a/browser.js b/browser.js deleted file mode 100644 index 3c259e1..0000000 --- a/browser.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); -//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map deleted file mode 100644 index 1fb93c0..0000000 --- a/browser.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"browser.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,EAIR,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,EAEN,OAAOR"} \ No newline at end of file diff --git a/index.js b/index.js deleted file mode 100644 index 635432d..0000000 --- a/index.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); -//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map deleted file mode 100644 index b2b182b..0000000 --- a/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,EAIR,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,EAEN,OAAOR"} \ No newline at end of file diff --git a/stats_browser.html b/stats_browser.html deleted file mode 100644 index 1438116..0000000 --- a/stats_browser.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - diff --git a/stats_node.html b/stats_node.html deleted file mode 100644 index 891fd19..0000000 --- a/stats_node.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 8a0fe02e9b45b6faa4e34ae79d8f3b0e4bac6e33 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 6 Jul 2022 19:00:17 +0000 Subject: [PATCH 010/158] 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 | 178 +- benchmark/benchmark.js | 112 - benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 152 - branches.md | 53 - browser.js | 3 + browser.js.map | 1 + docs/repl.txt | 39 - docs/types/index.d.ts | 177 -- docs/types/test.ts | 45 - examples/c/Makefile | 146 - examples/c/example.c | 50 - examples/index.js | 54 - .../stdlib/ndarray/base/broadcast_shapes.h | 40 - index.js | 3 + index.js.map | 1 + lib/index.js | 45 - lib/main.js | 256 -- manifest.json | 38 - package.json | 58 +- src/main.c | 118 - stats_browser.html | 2689 +++++++++++++++++ stats_node.html | 2689 +++++++++++++++++ test/test.js | 230 -- 46 files changed, 5424 insertions(+), 4713 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.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 branches.md create mode 100644 browser.js create mode 100644 browser.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/index.d.ts delete mode 100644 docs/types/test.ts delete mode 100644 examples/c/Makefile delete mode 100644 examples/c/example.c delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/broadcast_shapes.h create mode 100644 index.js create mode 100644 index.js.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 manifest.json delete mode 100644 src/main.c create mode 100644 stats_browser.html create mode 100644 stats_node.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 7f004ad..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 8a49110..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 +``` + +If no recognized module system is present, access bundle contents via the global scope: + +```html + ``` #### broadcastShapes( shapes ) @@ -232,9 +240,14 @@ var sh = broadcastShapes( [ sh1, sh2 ] ); -```javascript -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); +```html + + + + + + + + ```
@@ -275,131 +293,7 @@ for ( i = 0; i < shapes.length; i++ ) { -* * * - -
- -## C APIs - - - -
- -
- - - - - -
- -### Usage - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -``` - -#### stdlib_ndarray_broadcast_shapes( M, \*\*shapes, \*ndims, \*out ) - -Broadcasts array shapes to a single shape. - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -int64_t N1 = 4; -int64_t sh1[] = { 8, 1, 6, 1 }; - -int64_t N2 = 3; -int64_t sh2[] = { 7, 1, 5 }; - -int64_t ndims[] = { N1, N2 }; -int64_t *shapes[] = { sh1, sh2 }; - -int64_t out[] = { 0, 0, 0, 0 }; -int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -if ( status != 0 ) { - // Handle error... -} -``` - -The function accepts the following arguments: - -- **M**: `[in] int64_t` number of shape arrays. -- **shapes**: `[in] int64_t**` array of shape arrays (dimensions). -- **ndims**: `[in] int64_t*` number of dimensions for each respective shape array. -- **out**: `[out] int64_t*` output shape array. - -```c -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ); -``` - -If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). - -
- - - - - -
- -### Notes - -- Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. - -
- - - - - -
- -### Examples - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main() { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} -``` - -
- - - -
- diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index fa610dc..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,112 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pkg = require( './../package.json' ).name; -var broadcastShapes = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::two_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ] ], - [ [ 3, 2 ], [ 3, 1 ] ], - [ [ 1, 1 ], [ 2, 2 ] ], - [ [ 1 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::three_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::four_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ], [ 8, 1, 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ], [ 1, 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ], [ 1, 1, 2, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ], [ 1 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ], [ 5, 1, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/c/Makefile b/benchmark/c/Makefile deleted file mode 100644 index 5dc545c..0000000 --- a/benchmark/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := benchmark.out - - -# RULES # - -#/ -# Compiles C source files. -# -# @param {string} SOURCE_FILES - list of C source files -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lpthread -lblas`) -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [C_COMPILER] - C compiler -# @param {string} [CFLAGS] - C compiler flags -# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} SOURCE_FILES - list of C source files -# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {(string|void)} LIBRARIES - list of libraries (e.g., `-lpthread -lblas`) -# @param {(string|void)} LIBPATH - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} CC - C compiler -# @param {string} CFLAGS - C compiler flags -# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled benchmarks. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/benchmark/c/benchmark.c b/benchmark/c/benchmark.c deleted file mode 100644 index be62cd5..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,152 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/** -* Benchmark `broadcast_shapes`. -*/ -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "broadcast-shapes" -#define ITERATIONS 1000000 -#define REPEATS 3 - -/** -* Prints the TAP version. -*/ -void print_version() { - printf( "TAP version 13\n" ); -} - -/** -* Prints the TAP summary. -* -* @param total total number of tests -* @param passing total number of passing tests -*/ -void print_summary( int total, int passing ) { - printf( "#\n" ); - printf( "1..%d\n", total ); // TAP plan - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); -} - -/** -* Prints benchmarks results. -* -* @param elapsed elapsed time in seconds -*/ -void print_results( double elapsed ) { - double rate = (double)ITERATIONS / elapsed; - printf( " ---\n" ); - printf( " iterations: %d\n", ITERATIONS ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", rate ); - printf( " ...\n" ); -} - -/** -* Returns a clock time. -* -* @return clock time -*/ -double tic() { - struct timeval now; - gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; -} - -/** -* Generates a random double on the interval [0,1]. -* -* @return random double -*/ -double rand_double() { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark() { - double elapsed; - int8_t status; - double t; - int i; - - int64_t sh1[] = { 8, 1, 6, 1 }; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { 4, 3 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( out[ 0 ] != 8 ) { - printf( "unexpected result\n" ); - } - if ( out[ 1 ] != 7 ) { - printf( "unexpected result\n" ); - } - if ( out[ 2 ] != 6 ) { - printf( "unexpected result\n" ); - } - if ( out[ 3 ] != 5 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Main execution sequence. -*/ -int main( void ) { - double elapsed; - int i; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - for ( i = 0; i < REPEATS; i++ ) { - printf( "# c::native::%s::two_arrays\n", NAME ); - elapsed = benchmark(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", i+1 ); - } - print_summary( REPEATS, REPEATS ); -} diff --git a/branches.md b/branches.md deleted file mode 100644 index 20fbab5..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes" -click B href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/main" -click C href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production" -click D href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm \ No newline at end of file diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..3c259e1 --- /dev/null +++ b/browser.js @@ -0,0 +1,3 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map new file mode 100644 index 0000000..1fb93c0 --- /dev/null +++ b/browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"browser.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,EAIR,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,EAEN,OAAOR"} \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f1d92f6..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,39 +0,0 @@ - -{{alias}}( shapes ) - Broadcasts array shapes to a single shape. - - Two respective dimensions in two shape arrays are compatible if - - 1. the dimensions are equal. - 2. one dimension is `1`. - - The function returns `null` if provided incompatible shapes (i.e., shapes - which cannot be broadcast with one another). - - Parameters - ---------- - shapes: Array - Array of shape arrays. - - Returns - ------- - out: Array|null - Broadcast shape. - - Examples - -------- - // Compatible shapes: - > var sh1 = [ 8, 1, 6, 1 ]; - > var sh2 = [ 7, 1, 5 ]; - > var sh = {{alias}}( [ sh1, sh2 ] ) - [ 8, 7, 6, 5 ] - - // Incompatible shapes: - > sh1 = [ 3, 2 ]; - > sh1 = [ 2, 3 ]; - > sh = {{alias}}( [ sh1, sh2 ] ) - null - - See Also - -------- - diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts deleted file mode 100644 index f46767d..0000000 --- a/docs/types/index.d.ts +++ /dev/null @@ -1,177 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ArrayLike } from '@stdlib/types/array'; - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param shapes - array shapes -* @returns broadcast shape -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -declare function broadcastShapes( shapes: ArrayLike> ): ArrayLike; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = broadcastShapes; diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 2886539..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 broadcastShapes = require( './index' ); - - -// TESTS // - -// The function returns an array of numbers... -{ - broadcastShapes( [ [ 1, 2 ], [ 2, 2 ] ] ); // $ExpectType ArrayLike -} - -// The compiler throws an error if the function is not provided an array-like object containing array-like objects containing numbers... -{ - broadcastShapes( '5' ); // $ExpectError - broadcastShapes( 5 ); // $ExpectError - broadcastShapes( true ); // $ExpectError - broadcastShapes( false ); // $ExpectError - broadcastShapes( null ); // $ExpectError - broadcastShapes( {} ); // $ExpectError - broadcastShapes( [ '5' ] ); // $ExpectError - broadcastShapes( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - broadcastShapes(); // $ExpectError - broadcastShapes( [ [ 1, 2, 3 ] ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/c/Makefile b/examples/c/Makefile deleted file mode 100644 index 70c91f4..0000000 --- a/examples/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := example.out - - -# RULES # - -#/ -# Compiles source files. -# -# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) -# @param {string} [CFLAGS] - C compiler options -# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) -# @param {string} [SOURCE_FILES] - list of source files -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} CC - C compiler (e.g., `gcc`) -# @param {string} CFLAGS - C compiler options -# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) -# @param {string} SOURCE_FILES - list of source files -# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) -# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled examples. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/examples/c/example.c b/examples/c/example.c deleted file mode 100644 index fae2252..0000000 --- a/examples/c/example.c +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main() { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 28811f9..0000000 --- a/examples/index.js +++ /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. -*/ - -'use strict'; - -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( './../lib' ); - -var shapes; -var out; -var sh; -var i; -var j; - -function shape2string( shape ) { - return lpad( shape.join( ' x ' ), 20, ' ' ); -} - -shapes = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] -]; - -for ( i = 0; i < shapes.length; i++ ) { - sh = shapes[ i ]; - for ( j = 0; j < sh.length; j++ ) { - console.log( shape2string( sh[ j ] ) ); - } - console.log( lpad( '', 20, '-' ) ); - - out = broadcastShapes( sh ); - console.log( shape2string( out )+'\n' ); -} diff --git a/include/stdlib/ndarray/base/broadcast_shapes.h b/include/stdlib/ndarray/base/broadcast_shapes.h deleted file mode 100644 index e23dce1..0000000 --- a/include/stdlib/ndarray/base/broadcast_shapes.h +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#ifndef STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H -#define STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H - -#include - -/* -* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. -*/ -#ifdef __cplusplus -extern "C" { -#endif - -/** -* Broadcasts array shapes to a single shape. -*/ -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H diff --git a/index.js b/index.js new file mode 100644 index 0000000..635432d --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map new file mode 100644 index 0000000..b2b182b --- /dev/null +++ b/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,EAIR,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,EAEN,OAAOR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 0c9817e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Broadcast array shapes to a single shape. -* -* @module @stdlib/ndarray-base-broadcast-shapes -* -* @example -* var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); -* -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -*/ - -// 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 8558e60..0000000 --- a/lib/main.js +++ /dev/null @@ -1,256 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param {Array} shapes - array of shape arrays -* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`) -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [ 8, 0, 1, 6, 1 ], -* [ 8, 8, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -function broadcastShapes( shapes ) { - var ndims; - var out; - var dim; - var sh; - var n1; - var n2; - var d; - var M; - var N; - var i; - var j; - - M = shapes.length; - out = []; - if ( M === 0 ) { - return out; - } - sh = shapes[ 0 ]; - N = sh.length; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M === 1 ) { - // Need to manually copy to output shape, as shapes could be array-like objects... - for ( i = 0; i < N; i++ ) { - out.push( sh[ i ] ); - } - return out; - } - // Determine the maximum dimensionality... - ndims = [ N ]; - for ( i = 1; i < M; i++ ) { - ndims.push( shapes[ i ].length ); - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Initialize the output array... - for ( i = 0; i < N; i++ ) { - out.push( 0 ); - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim === 1 ) { - dim = d; - continue; - } - if ( d === 1 || dim === d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return null; - } - out[ i ] = dim; - i -= 1; - } - return out; -} - - -// EXPORTS // - -module.exports = broadcastShapes; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 890a937..0000000 --- a/manifest.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "options": {}, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [] - } - ] -} diff --git a/package.json b/package.json index 71ded4c..096d386 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,7 @@ "version": "0.0.8", "description": "Broadcast array shapes to a single shape.", "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", - "include": "./include", - "lib": "./lib", - "src": "./src", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "main": "./index.js", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,33 +12,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/types": "^0.0.x", - "@stdlib/utils-library-manifest": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x" - }, - "devDependencies": { - "@stdlib/bench": "^0.0.x", - "@stdlib/string-left-pad": "^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", "stdtypes", @@ -80,9 +27,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" } -} \ No newline at end of file +} diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 35a3654..0000000 --- a/src/main.c +++ /dev/null @@ -1,118 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). -* -* - Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. -* -* @param M number of array shapes -* @param shapes pointer to an array containing shape arrays -* @param ndims array containing the number of dimensions for (i.e., length of) each respective shape array -* @param out pointer to output array -* @return status -* -* @example -* #include "stdlib/ndarray/base/broadcast_shapes.h" -* #include -* -* int64_t N1 = 4; -* int64_t sh1[] = { 8, 1, 6, 1 }; -* -* int64_t N2 = 3; -* int64_t sh2[] = { 7, 1, 5 }; -* -* int64_t ndims[] = { N1, N2 }; -* int64_t *shapes[] = { sh1, sh2 }; -* -* int64_t out[] = { 0, 0, 0, 0 }; -* int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -*/ -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ) { - int64_t dim; - int64_t *sh; - int64_t n1; - int64_t n2; - int64_t d; - int64_t N; - int64_t i; - int64_t j; - - if ( M == 0 ) { - return 0; - } - sh = shapes[ 0 ]; - N = ndims[ 0 ]; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M == 1 ) { - for ( i = 0; i < N; i++ ) { - out[ i ] = sh[ i ]; - } - return 0; - } - // Determine the maximum dimensionality... - for ( i = 1; i < M; i++ ) { - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim == 1 ) { - dim = d; - continue; - } - if ( d == 1 || dim == d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return -1; - } - out[ i ] = dim; - i -= 1; - } - return 0; -} diff --git a/stats_browser.html b/stats_browser.html new file mode 100644 index 0000000..4852697 --- /dev/null +++ b/stats_browser.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/stats_node.html b/stats_node.html new file mode 100644 index 0000000..5d6750e --- /dev/null +++ b/stats_node.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 63f703c..0000000 --- a/test/test.js +++ /dev/null @@ -1,230 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var broadcastShapes = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastShapes, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] - ]; - - expected = [ - [ 1, 2 ], - [ 3, 4 ], - [ 5, 6, 7 ], - [ 3, 3 ], - [ 3 ], - [ 3, 2 ], - [ 2, 3 ], - [ 1, 2 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty dims)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 0 ], [ 0, 0 ] ], - [ [ 0, 1 ], [ 0, 0 ] ], - [ [ 1, 0 ], [ 0, 1 ] ], - [ [ 1, 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 1, 0 ] ], - [ [ 1, 1 ], [ 0, 1 ] ], - [ [ 0 ], [ 0, 0 ] ], - [ [ 0 ], [ 0, 1 ] ], - [ [ 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 0 ] ], - [ [ 1 ], [ 0, 1 ] ], - [ [ 1 ], [ 1, 0 ] ], - [ [ 1 ], [ 8, 0 ] ], - [ [ 8, 1, 6, 1 ], [ 0, 1, 5 ] ], - [ [ 8, 0, 6, 1 ], [ 1, 5 ] ] - ]; - - expected = [ - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 1, 0 ], - [ 8, 0 ], - [ 8, 0, 6, 5 ], - [ 8, 0, 6, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (no shapes)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [] - ]; - - expected = [ - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty shapes (i.e., zero-dimensional array broadcasting))', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [] ], - [ [], [] ], - [ [], [], [] ], - [ [], [ 0 ] ], - [ [ 0 ], [] ], - [ [], [ 0, 0 ] ], - [ [ 0, 0 ], [] ], - [ [], [ 1, 0 ] ], - [ [], [ 0, 1 ] ], - [ [], [ 3, 3 ] ], - [ [], [ 3, 3 ], [] ] - ]; - - expected = [ - [], - [], - [], - [ 0 ], - [ 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 3, 3 ], - [ 3, 3 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (single shape)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 7 ] ], - [ [ 1, 1 ] ], - [ [ 5, 6, 1 ] ] - ]; - - expected = [ - [ 7 ], - [ 1, 1 ], - [ 5, 6, 1 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function returns `null` if provided incompatible shapes', function test( t ) { - var actual; - var values; - var i; - - values = [ - [ [ 3 ], [ 4 ] ], - [ [ 2, 3 ], [ 2 ] ], - [ [ 3 ], [ 3 ], [ 4 ] ], - [ [ 1, 3, 4 ], [ 2, 3, 3 ] ], - [ [ 1, 2 ], [ 3, 1 ], [ 3, 2 ], [ 10, 5 ] ], - [ [ 2 ], [ 2, 3 ] ], - [ [ 2 ], [ 2 ], [ 2 ], [ 2 ], [ 3 ], [ 3 ], [ 3 ], [ 3 ] ], - [ [ 9, 0, 9 ], [ 0, 9, 0 ] ], - [ [ 9, 9, 9 ], [ 0, 9, 9 ] ], - [ [ 9, 0, 9 ], [ 9, 9, 9 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 0 ] ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.strictEqual( actual, null, 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); From 0a30a2a14eb2e39577e0284c6d19bb533acbb481 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Aug 2022 03:26:38 +0000 Subject: [PATCH 011/158] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index e004d17..71ded4c 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,8 @@ }, "dependencies": { "@stdlib/types": "^0.0.x", - "@stdlib/utils-library-manifest": "^0.0.x" + "@stdlib/utils-library-manifest": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x" }, "devDependencies": { "@stdlib/bench": "^0.0.x", @@ -84,4 +85,4 @@ "type": "patreon", "url": "https://www.patreon.com/athan" } -} +} \ No newline at end of file From 11c64003db2dcb75c4c2425dbb7398c09d9bb3db Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Aug 2022 13:33:07 +0000 Subject: [PATCH 012/158] Remove files --- browser.js | 3 - browser.js.map | 1 - index.js | 3 - index.js.map | 1 - stats_browser.html | 2689 -------------------------------------------- stats_node.html | 2689 -------------------------------------------- 6 files changed, 5386 deletions(-) delete mode 100644 browser.js delete mode 100644 browser.js.map delete mode 100644 index.js delete mode 100644 index.js.map delete mode 100644 stats_browser.html delete mode 100644 stats_node.html diff --git a/browser.js b/browser.js deleted file mode 100644 index 3c259e1..0000000 --- a/browser.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); -//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map deleted file mode 100644 index 1fb93c0..0000000 --- a/browser.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"browser.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,EAIR,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,EAEN,OAAOR"} \ No newline at end of file diff --git a/index.js b/index.js deleted file mode 100644 index 635432d..0000000 --- a/index.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); -//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map deleted file mode 100644 index b2b182b..0000000 --- a/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,EAIR,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,EAEN,OAAOR"} \ No newline at end of file diff --git a/stats_browser.html b/stats_browser.html deleted file mode 100644 index 4852697..0000000 --- a/stats_browser.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - diff --git a/stats_node.html b/stats_node.html deleted file mode 100644 index 5d6750e..0000000 --- a/stats_node.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 42bc2a4464da0a3919231c0c0a973c47732463ef Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Aug 2022 13:33:59 +0000 Subject: [PATCH 013/158] 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 | 178 +- benchmark/benchmark.js | 112 - benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 152 - branches.md | 53 - browser.js | 3 + browser.js.map | 1 + docs/repl.txt | 39 - docs/types/index.d.ts | 177 -- docs/types/test.ts | 45 - examples/c/Makefile | 146 - examples/c/example.c | 50 - examples/index.js | 54 - .../stdlib/ndarray/base/broadcast_shapes.h | 40 - index.js | 3 + index.js.map | 1 + lib/index.js | 45 - lib/main.js | 256 -- manifest.json | 38 - package.json | 58 +- src/main.c | 118 - stats_browser.html | 2689 +++++++++++++++++ stats_node.html | 2689 +++++++++++++++++ test/test.js | 230 -- 47 files changed, 5424 insertions(+), 4787 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.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 branches.md create mode 100644 browser.js create mode 100644 browser.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/index.d.ts delete mode 100644 docs/types/test.ts delete mode 100644 examples/c/Makefile delete mode 100644 examples/c/example.c delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/broadcast_shapes.h create mode 100644 index.js create mode 100644 index.js.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 manifest.json delete mode 100644 src/main.c create mode 100644 stats_browser.html create mode 100644 stats_node.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 72fd23d..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-08-01T00:50:12.838Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 7f004ad..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 8a49110..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 +``` + +If no recognized module system is present, access bundle contents via the global scope: + +```html + ``` #### broadcastShapes( shapes ) @@ -232,9 +240,14 @@ var sh = broadcastShapes( [ sh1, sh2 ] ); -```javascript -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); +```html + + + + + + + + ```
@@ -275,131 +293,7 @@ for ( i = 0; i < shapes.length; i++ ) { -* * * - -
- -## C APIs - - - -
- -
- - - - - -
- -### Usage - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -``` - -#### stdlib_ndarray_broadcast_shapes( M, \*\*shapes, \*ndims, \*out ) - -Broadcasts array shapes to a single shape. - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -int64_t N1 = 4; -int64_t sh1[] = { 8, 1, 6, 1 }; - -int64_t N2 = 3; -int64_t sh2[] = { 7, 1, 5 }; - -int64_t ndims[] = { N1, N2 }; -int64_t *shapes[] = { sh1, sh2 }; - -int64_t out[] = { 0, 0, 0, 0 }; -int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -if ( status != 0 ) { - // Handle error... -} -``` - -The function accepts the following arguments: - -- **M**: `[in] int64_t` number of shape arrays. -- **shapes**: `[in] int64_t**` array of shape arrays (dimensions). -- **ndims**: `[in] int64_t*` number of dimensions for each respective shape array. -- **out**: `[out] int64_t*` output shape array. - -```c -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ); -``` - -If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). - -
- - - - - -
- -### Notes - -- Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. - -
- - - - - -
- -### Examples - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main() { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} -``` - -
- - - -
- diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index fa610dc..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,112 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pkg = require( './../package.json' ).name; -var broadcastShapes = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::two_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ] ], - [ [ 3, 2 ], [ 3, 1 ] ], - [ [ 1, 1 ], [ 2, 2 ] ], - [ [ 1 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::three_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::four_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ], [ 8, 1, 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ], [ 1, 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ], [ 1, 1, 2, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ], [ 1 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ], [ 5, 1, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/c/Makefile b/benchmark/c/Makefile deleted file mode 100644 index 5dc545c..0000000 --- a/benchmark/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := benchmark.out - - -# RULES # - -#/ -# Compiles C source files. -# -# @param {string} SOURCE_FILES - list of C source files -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lpthread -lblas`) -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [C_COMPILER] - C compiler -# @param {string} [CFLAGS] - C compiler flags -# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} SOURCE_FILES - list of C source files -# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {(string|void)} LIBRARIES - list of libraries (e.g., `-lpthread -lblas`) -# @param {(string|void)} LIBPATH - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} CC - C compiler -# @param {string} CFLAGS - C compiler flags -# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled benchmarks. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/benchmark/c/benchmark.c b/benchmark/c/benchmark.c deleted file mode 100644 index be62cd5..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,152 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/** -* Benchmark `broadcast_shapes`. -*/ -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "broadcast-shapes" -#define ITERATIONS 1000000 -#define REPEATS 3 - -/** -* Prints the TAP version. -*/ -void print_version() { - printf( "TAP version 13\n" ); -} - -/** -* Prints the TAP summary. -* -* @param total total number of tests -* @param passing total number of passing tests -*/ -void print_summary( int total, int passing ) { - printf( "#\n" ); - printf( "1..%d\n", total ); // TAP plan - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); -} - -/** -* Prints benchmarks results. -* -* @param elapsed elapsed time in seconds -*/ -void print_results( double elapsed ) { - double rate = (double)ITERATIONS / elapsed; - printf( " ---\n" ); - printf( " iterations: %d\n", ITERATIONS ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", rate ); - printf( " ...\n" ); -} - -/** -* Returns a clock time. -* -* @return clock time -*/ -double tic() { - struct timeval now; - gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; -} - -/** -* Generates a random double on the interval [0,1]. -* -* @return random double -*/ -double rand_double() { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark() { - double elapsed; - int8_t status; - double t; - int i; - - int64_t sh1[] = { 8, 1, 6, 1 }; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { 4, 3 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( out[ 0 ] != 8 ) { - printf( "unexpected result\n" ); - } - if ( out[ 1 ] != 7 ) { - printf( "unexpected result\n" ); - } - if ( out[ 2 ] != 6 ) { - printf( "unexpected result\n" ); - } - if ( out[ 3 ] != 5 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Main execution sequence. -*/ -int main( void ) { - double elapsed; - int i; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - for ( i = 0; i < REPEATS; i++ ) { - printf( "# c::native::%s::two_arrays\n", NAME ); - elapsed = benchmark(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", i+1 ); - } - print_summary( REPEATS, REPEATS ); -} diff --git a/branches.md b/branches.md deleted file mode 100644 index 20fbab5..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes" -click B href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/main" -click C href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production" -click D href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm \ No newline at end of file diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..3c259e1 --- /dev/null +++ b/browser.js @@ -0,0 +1,3 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map new file mode 100644 index 0000000..1fb93c0 --- /dev/null +++ b/browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"browser.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,EAIR,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,EAEN,OAAOR"} \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f1d92f6..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,39 +0,0 @@ - -{{alias}}( shapes ) - Broadcasts array shapes to a single shape. - - Two respective dimensions in two shape arrays are compatible if - - 1. the dimensions are equal. - 2. one dimension is `1`. - - The function returns `null` if provided incompatible shapes (i.e., shapes - which cannot be broadcast with one another). - - Parameters - ---------- - shapes: Array - Array of shape arrays. - - Returns - ------- - out: Array|null - Broadcast shape. - - Examples - -------- - // Compatible shapes: - > var sh1 = [ 8, 1, 6, 1 ]; - > var sh2 = [ 7, 1, 5 ]; - > var sh = {{alias}}( [ sh1, sh2 ] ) - [ 8, 7, 6, 5 ] - - // Incompatible shapes: - > sh1 = [ 3, 2 ]; - > sh1 = [ 2, 3 ]; - > sh = {{alias}}( [ sh1, sh2 ] ) - null - - See Also - -------- - diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts deleted file mode 100644 index f46767d..0000000 --- a/docs/types/index.d.ts +++ /dev/null @@ -1,177 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ArrayLike } from '@stdlib/types/array'; - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param shapes - array shapes -* @returns broadcast shape -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -declare function broadcastShapes( shapes: ArrayLike> ): ArrayLike; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = broadcastShapes; diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 2886539..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 broadcastShapes = require( './index' ); - - -// TESTS // - -// The function returns an array of numbers... -{ - broadcastShapes( [ [ 1, 2 ], [ 2, 2 ] ] ); // $ExpectType ArrayLike -} - -// The compiler throws an error if the function is not provided an array-like object containing array-like objects containing numbers... -{ - broadcastShapes( '5' ); // $ExpectError - broadcastShapes( 5 ); // $ExpectError - broadcastShapes( true ); // $ExpectError - broadcastShapes( false ); // $ExpectError - broadcastShapes( null ); // $ExpectError - broadcastShapes( {} ); // $ExpectError - broadcastShapes( [ '5' ] ); // $ExpectError - broadcastShapes( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - broadcastShapes(); // $ExpectError - broadcastShapes( [ [ 1, 2, 3 ] ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/c/Makefile b/examples/c/Makefile deleted file mode 100644 index 70c91f4..0000000 --- a/examples/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := example.out - - -# RULES # - -#/ -# Compiles source files. -# -# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) -# @param {string} [CFLAGS] - C compiler options -# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) -# @param {string} [SOURCE_FILES] - list of source files -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} CC - C compiler (e.g., `gcc`) -# @param {string} CFLAGS - C compiler options -# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) -# @param {string} SOURCE_FILES - list of source files -# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) -# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled examples. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/examples/c/example.c b/examples/c/example.c deleted file mode 100644 index fae2252..0000000 --- a/examples/c/example.c +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main() { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 28811f9..0000000 --- a/examples/index.js +++ /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. -*/ - -'use strict'; - -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( './../lib' ); - -var shapes; -var out; -var sh; -var i; -var j; - -function shape2string( shape ) { - return lpad( shape.join( ' x ' ), 20, ' ' ); -} - -shapes = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] -]; - -for ( i = 0; i < shapes.length; i++ ) { - sh = shapes[ i ]; - for ( j = 0; j < sh.length; j++ ) { - console.log( shape2string( sh[ j ] ) ); - } - console.log( lpad( '', 20, '-' ) ); - - out = broadcastShapes( sh ); - console.log( shape2string( out )+'\n' ); -} diff --git a/include/stdlib/ndarray/base/broadcast_shapes.h b/include/stdlib/ndarray/base/broadcast_shapes.h deleted file mode 100644 index e23dce1..0000000 --- a/include/stdlib/ndarray/base/broadcast_shapes.h +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#ifndef STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H -#define STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H - -#include - -/* -* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. -*/ -#ifdef __cplusplus -extern "C" { -#endif - -/** -* Broadcasts array shapes to a single shape. -*/ -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H diff --git a/index.js b/index.js new file mode 100644 index 0000000..635432d --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map new file mode 100644 index 0000000..b2b182b --- /dev/null +++ b/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,EAIR,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,EAEN,OAAOR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 0c9817e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Broadcast array shapes to a single shape. -* -* @module @stdlib/ndarray-base-broadcast-shapes -* -* @example -* var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); -* -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -*/ - -// 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 8558e60..0000000 --- a/lib/main.js +++ /dev/null @@ -1,256 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param {Array} shapes - array of shape arrays -* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`) -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [ 8, 0, 1, 6, 1 ], -* [ 8, 8, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -function broadcastShapes( shapes ) { - var ndims; - var out; - var dim; - var sh; - var n1; - var n2; - var d; - var M; - var N; - var i; - var j; - - M = shapes.length; - out = []; - if ( M === 0 ) { - return out; - } - sh = shapes[ 0 ]; - N = sh.length; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M === 1 ) { - // Need to manually copy to output shape, as shapes could be array-like objects... - for ( i = 0; i < N; i++ ) { - out.push( sh[ i ] ); - } - return out; - } - // Determine the maximum dimensionality... - ndims = [ N ]; - for ( i = 1; i < M; i++ ) { - ndims.push( shapes[ i ].length ); - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Initialize the output array... - for ( i = 0; i < N; i++ ) { - out.push( 0 ); - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim === 1 ) { - dim = d; - continue; - } - if ( d === 1 || dim === d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return null; - } - out[ i ] = dim; - i -= 1; - } - return out; -} - - -// EXPORTS // - -module.exports = broadcastShapes; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 890a937..0000000 --- a/manifest.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "options": {}, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [] - } - ] -} diff --git a/package.json b/package.json index 71ded4c..096d386 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,7 @@ "version": "0.0.8", "description": "Broadcast array shapes to a single shape.", "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", - "include": "./include", - "lib": "./lib", - "src": "./src", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "main": "./index.js", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,33 +12,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/types": "^0.0.x", - "@stdlib/utils-library-manifest": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x" - }, - "devDependencies": { - "@stdlib/bench": "^0.0.x", - "@stdlib/string-left-pad": "^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", "stdtypes", @@ -80,9 +27,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" } -} \ No newline at end of file +} diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 35a3654..0000000 --- a/src/main.c +++ /dev/null @@ -1,118 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). -* -* - Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. -* -* @param M number of array shapes -* @param shapes pointer to an array containing shape arrays -* @param ndims array containing the number of dimensions for (i.e., length of) each respective shape array -* @param out pointer to output array -* @return status -* -* @example -* #include "stdlib/ndarray/base/broadcast_shapes.h" -* #include -* -* int64_t N1 = 4; -* int64_t sh1[] = { 8, 1, 6, 1 }; -* -* int64_t N2 = 3; -* int64_t sh2[] = { 7, 1, 5 }; -* -* int64_t ndims[] = { N1, N2 }; -* int64_t *shapes[] = { sh1, sh2 }; -* -* int64_t out[] = { 0, 0, 0, 0 }; -* int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -*/ -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ) { - int64_t dim; - int64_t *sh; - int64_t n1; - int64_t n2; - int64_t d; - int64_t N; - int64_t i; - int64_t j; - - if ( M == 0 ) { - return 0; - } - sh = shapes[ 0 ]; - N = ndims[ 0 ]; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M == 1 ) { - for ( i = 0; i < N; i++ ) { - out[ i ] = sh[ i ]; - } - return 0; - } - // Determine the maximum dimensionality... - for ( i = 1; i < M; i++ ) { - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim == 1 ) { - dim = d; - continue; - } - if ( d == 1 || dim == d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return -1; - } - out[ i ] = dim; - i -= 1; - } - return 0; -} diff --git a/stats_browser.html b/stats_browser.html new file mode 100644 index 0000000..66e9e08 --- /dev/null +++ b/stats_browser.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/stats_node.html b/stats_node.html new file mode 100644 index 0000000..3105567 --- /dev/null +++ b/stats_node.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 63f703c..0000000 --- a/test/test.js +++ /dev/null @@ -1,230 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var broadcastShapes = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastShapes, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] - ]; - - expected = [ - [ 1, 2 ], - [ 3, 4 ], - [ 5, 6, 7 ], - [ 3, 3 ], - [ 3 ], - [ 3, 2 ], - [ 2, 3 ], - [ 1, 2 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty dims)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 0 ], [ 0, 0 ] ], - [ [ 0, 1 ], [ 0, 0 ] ], - [ [ 1, 0 ], [ 0, 1 ] ], - [ [ 1, 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 1, 0 ] ], - [ [ 1, 1 ], [ 0, 1 ] ], - [ [ 0 ], [ 0, 0 ] ], - [ [ 0 ], [ 0, 1 ] ], - [ [ 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 0 ] ], - [ [ 1 ], [ 0, 1 ] ], - [ [ 1 ], [ 1, 0 ] ], - [ [ 1 ], [ 8, 0 ] ], - [ [ 8, 1, 6, 1 ], [ 0, 1, 5 ] ], - [ [ 8, 0, 6, 1 ], [ 1, 5 ] ] - ]; - - expected = [ - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 1, 0 ], - [ 8, 0 ], - [ 8, 0, 6, 5 ], - [ 8, 0, 6, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (no shapes)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [] - ]; - - expected = [ - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty shapes (i.e., zero-dimensional array broadcasting))', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [] ], - [ [], [] ], - [ [], [], [] ], - [ [], [ 0 ] ], - [ [ 0 ], [] ], - [ [], [ 0, 0 ] ], - [ [ 0, 0 ], [] ], - [ [], [ 1, 0 ] ], - [ [], [ 0, 1 ] ], - [ [], [ 3, 3 ] ], - [ [], [ 3, 3 ], [] ] - ]; - - expected = [ - [], - [], - [], - [ 0 ], - [ 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 3, 3 ], - [ 3, 3 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (single shape)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 7 ] ], - [ [ 1, 1 ] ], - [ [ 5, 6, 1 ] ] - ]; - - expected = [ - [ 7 ], - [ 1, 1 ], - [ 5, 6, 1 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function returns `null` if provided incompatible shapes', function test( t ) { - var actual; - var values; - var i; - - values = [ - [ [ 3 ], [ 4 ] ], - [ [ 2, 3 ], [ 2 ] ], - [ [ 3 ], [ 3 ], [ 4 ] ], - [ [ 1, 3, 4 ], [ 2, 3, 3 ] ], - [ [ 1, 2 ], [ 3, 1 ], [ 3, 2 ], [ 10, 5 ] ], - [ [ 2 ], [ 2, 3 ] ], - [ [ 2 ], [ 2 ], [ 2 ], [ 2 ], [ 3 ], [ 3 ], [ 3 ], [ 3 ] ], - [ [ 9, 0, 9 ], [ 0, 9, 0 ] ], - [ [ 9, 9, 9 ], [ 0, 9, 9 ] ], - [ [ 9, 0, 9 ], [ 9, 9, 9 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 0 ] ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.strictEqual( actual, null, 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); From 2736833d2c853cb675cb3deec22cbd7915549d4b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Sep 2022 03:17:22 +0000 Subject: [PATCH 014/158] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index e004d17..71ded4c 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,8 @@ }, "dependencies": { "@stdlib/types": "^0.0.x", - "@stdlib/utils-library-manifest": "^0.0.x" + "@stdlib/utils-library-manifest": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x" }, "devDependencies": { "@stdlib/bench": "^0.0.x", @@ -84,4 +85,4 @@ "type": "patreon", "url": "https://www.patreon.com/athan" } -} +} \ No newline at end of file From af07dd9ac2e02afc06058d10acf7c452637629b0 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Sep 2022 13:05:41 +0000 Subject: [PATCH 015/158] Remove files --- browser.js | 3 - browser.js.map | 1 - index.js | 3 - index.js.map | 1 - stats_browser.html | 2689 -------------------------------------------- stats_node.html | 2689 -------------------------------------------- 6 files changed, 5386 deletions(-) delete mode 100644 browser.js delete mode 100644 browser.js.map delete mode 100644 index.js delete mode 100644 index.js.map delete mode 100644 stats_browser.html delete mode 100644 stats_node.html diff --git a/browser.js b/browser.js deleted file mode 100644 index 3c259e1..0000000 --- a/browser.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); -//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map deleted file mode 100644 index 1fb93c0..0000000 --- a/browser.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"browser.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,EAIR,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,EAEN,OAAOR"} \ No newline at end of file diff --git a/index.js b/index.js deleted file mode 100644 index 635432d..0000000 --- a/index.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); -//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map deleted file mode 100644 index b2b182b..0000000 --- a/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,EAIR,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,EAEN,OAAOR"} \ No newline at end of file diff --git a/stats_browser.html b/stats_browser.html deleted file mode 100644 index 66e9e08..0000000 --- a/stats_browser.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - diff --git a/stats_node.html b/stats_node.html deleted file mode 100644 index 3105567..0000000 --- a/stats_node.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 6620870b32b894da4cb21d7d55320c564ab932f8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Sep 2022 13:06:34 +0000 Subject: [PATCH 016/158] 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 | 178 +- benchmark/benchmark.js | 112 - benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 152 - branches.md | 53 - browser.js | 3 + browser.js.map | 1 + docs/repl.txt | 39 - docs/types/index.d.ts | 177 -- docs/types/test.ts | 45 - examples/c/Makefile | 146 - examples/c/example.c | 50 - examples/index.js | 54 - .../stdlib/ndarray/base/broadcast_shapes.h | 40 - index.js | 3 + index.js.map | 1 + lib/index.js | 45 - lib/main.js | 256 -- manifest.json | 38 - package.json | 58 +- src/main.c | 118 - stats_browser.html | 2689 +++++++++++++++++ stats_node.html | 2689 +++++++++++++++++ test/test.js | 230 -- 47 files changed, 5424 insertions(+), 4803 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.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 branches.md create mode 100644 browser.js create mode 100644 browser.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/index.d.ts delete mode 100644 docs/types/test.ts delete mode 100644 examples/c/Makefile delete mode 100644 examples/c/example.c delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/broadcast_shapes.h create mode 100644 index.js create mode 100644 index.js.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 manifest.json delete mode 100644 src/main.c create mode 100644 stats_browser.html create mode 100644 stats_node.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 485db69..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-09-01T00:46:04.860Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 7f004ad..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 8a49110..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 +``` + +If no recognized module system is present, access bundle contents via the global scope: + +```html + ``` #### broadcastShapes( shapes ) @@ -232,9 +240,14 @@ var sh = broadcastShapes( [ sh1, sh2 ] ); -```javascript -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); +```html + + + + + + + + ```
@@ -275,131 +293,7 @@ for ( i = 0; i < shapes.length; i++ ) { -* * * - -
- -## C APIs - - - -
- -
- - - - - -
- -### Usage - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -``` - -#### stdlib_ndarray_broadcast_shapes( M, \*\*shapes, \*ndims, \*out ) - -Broadcasts array shapes to a single shape. - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -int64_t N1 = 4; -int64_t sh1[] = { 8, 1, 6, 1 }; - -int64_t N2 = 3; -int64_t sh2[] = { 7, 1, 5 }; - -int64_t ndims[] = { N1, N2 }; -int64_t *shapes[] = { sh1, sh2 }; - -int64_t out[] = { 0, 0, 0, 0 }; -int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -if ( status != 0 ) { - // Handle error... -} -``` - -The function accepts the following arguments: - -- **M**: `[in] int64_t` number of shape arrays. -- **shapes**: `[in] int64_t**` array of shape arrays (dimensions). -- **ndims**: `[in] int64_t*` number of dimensions for each respective shape array. -- **out**: `[out] int64_t*` output shape array. - -```c -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ); -``` - -If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). - -
- - - - - -
- -### Notes - -- Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. - -
- - - - - -
- -### Examples - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main() { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} -``` - -
- - - -
- diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index fa610dc..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,112 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pkg = require( './../package.json' ).name; -var broadcastShapes = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::two_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ] ], - [ [ 3, 2 ], [ 3, 1 ] ], - [ [ 1, 1 ], [ 2, 2 ] ], - [ [ 1 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::three_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::four_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ], [ 8, 1, 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ], [ 1, 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ], [ 1, 1, 2, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ], [ 1 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ], [ 5, 1, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/c/Makefile b/benchmark/c/Makefile deleted file mode 100644 index 5dc545c..0000000 --- a/benchmark/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := benchmark.out - - -# RULES # - -#/ -# Compiles C source files. -# -# @param {string} SOURCE_FILES - list of C source files -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lpthread -lblas`) -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [C_COMPILER] - C compiler -# @param {string} [CFLAGS] - C compiler flags -# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} SOURCE_FILES - list of C source files -# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {(string|void)} LIBRARIES - list of libraries (e.g., `-lpthread -lblas`) -# @param {(string|void)} LIBPATH - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} CC - C compiler -# @param {string} CFLAGS - C compiler flags -# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled benchmarks. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/benchmark/c/benchmark.c b/benchmark/c/benchmark.c deleted file mode 100644 index be62cd5..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,152 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/** -* Benchmark `broadcast_shapes`. -*/ -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "broadcast-shapes" -#define ITERATIONS 1000000 -#define REPEATS 3 - -/** -* Prints the TAP version. -*/ -void print_version() { - printf( "TAP version 13\n" ); -} - -/** -* Prints the TAP summary. -* -* @param total total number of tests -* @param passing total number of passing tests -*/ -void print_summary( int total, int passing ) { - printf( "#\n" ); - printf( "1..%d\n", total ); // TAP plan - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); -} - -/** -* Prints benchmarks results. -* -* @param elapsed elapsed time in seconds -*/ -void print_results( double elapsed ) { - double rate = (double)ITERATIONS / elapsed; - printf( " ---\n" ); - printf( " iterations: %d\n", ITERATIONS ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", rate ); - printf( " ...\n" ); -} - -/** -* Returns a clock time. -* -* @return clock time -*/ -double tic() { - struct timeval now; - gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; -} - -/** -* Generates a random double on the interval [0,1]. -* -* @return random double -*/ -double rand_double() { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark() { - double elapsed; - int8_t status; - double t; - int i; - - int64_t sh1[] = { 8, 1, 6, 1 }; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { 4, 3 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( out[ 0 ] != 8 ) { - printf( "unexpected result\n" ); - } - if ( out[ 1 ] != 7 ) { - printf( "unexpected result\n" ); - } - if ( out[ 2 ] != 6 ) { - printf( "unexpected result\n" ); - } - if ( out[ 3 ] != 5 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Main execution sequence. -*/ -int main( void ) { - double elapsed; - int i; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - for ( i = 0; i < REPEATS; i++ ) { - printf( "# c::native::%s::two_arrays\n", NAME ); - elapsed = benchmark(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", i+1 ); - } - print_summary( REPEATS, REPEATS ); -} diff --git a/branches.md b/branches.md deleted file mode 100644 index 20fbab5..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes" -click B href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/main" -click C href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production" -click D href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm \ No newline at end of file diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..3c259e1 --- /dev/null +++ b/browser.js @@ -0,0 +1,3 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map new file mode 100644 index 0000000..1fb93c0 --- /dev/null +++ b/browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"browser.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,EAIR,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,EAEN,OAAOR"} \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f1d92f6..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,39 +0,0 @@ - -{{alias}}( shapes ) - Broadcasts array shapes to a single shape. - - Two respective dimensions in two shape arrays are compatible if - - 1. the dimensions are equal. - 2. one dimension is `1`. - - The function returns `null` if provided incompatible shapes (i.e., shapes - which cannot be broadcast with one another). - - Parameters - ---------- - shapes: Array - Array of shape arrays. - - Returns - ------- - out: Array|null - Broadcast shape. - - Examples - -------- - // Compatible shapes: - > var sh1 = [ 8, 1, 6, 1 ]; - > var sh2 = [ 7, 1, 5 ]; - > var sh = {{alias}}( [ sh1, sh2 ] ) - [ 8, 7, 6, 5 ] - - // Incompatible shapes: - > sh1 = [ 3, 2 ]; - > sh1 = [ 2, 3 ]; - > sh = {{alias}}( [ sh1, sh2 ] ) - null - - See Also - -------- - diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts deleted file mode 100644 index f46767d..0000000 --- a/docs/types/index.d.ts +++ /dev/null @@ -1,177 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ArrayLike } from '@stdlib/types/array'; - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param shapes - array shapes -* @returns broadcast shape -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -declare function broadcastShapes( shapes: ArrayLike> ): ArrayLike; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = broadcastShapes; diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 2886539..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 broadcastShapes = require( './index' ); - - -// TESTS // - -// The function returns an array of numbers... -{ - broadcastShapes( [ [ 1, 2 ], [ 2, 2 ] ] ); // $ExpectType ArrayLike -} - -// The compiler throws an error if the function is not provided an array-like object containing array-like objects containing numbers... -{ - broadcastShapes( '5' ); // $ExpectError - broadcastShapes( 5 ); // $ExpectError - broadcastShapes( true ); // $ExpectError - broadcastShapes( false ); // $ExpectError - broadcastShapes( null ); // $ExpectError - broadcastShapes( {} ); // $ExpectError - broadcastShapes( [ '5' ] ); // $ExpectError - broadcastShapes( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - broadcastShapes(); // $ExpectError - broadcastShapes( [ [ 1, 2, 3 ] ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/c/Makefile b/examples/c/Makefile deleted file mode 100644 index 70c91f4..0000000 --- a/examples/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := example.out - - -# RULES # - -#/ -# Compiles source files. -# -# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) -# @param {string} [CFLAGS] - C compiler options -# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) -# @param {string} [SOURCE_FILES] - list of source files -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} CC - C compiler (e.g., `gcc`) -# @param {string} CFLAGS - C compiler options -# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) -# @param {string} SOURCE_FILES - list of source files -# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) -# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled examples. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/examples/c/example.c b/examples/c/example.c deleted file mode 100644 index fae2252..0000000 --- a/examples/c/example.c +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main() { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 28811f9..0000000 --- a/examples/index.js +++ /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. -*/ - -'use strict'; - -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( './../lib' ); - -var shapes; -var out; -var sh; -var i; -var j; - -function shape2string( shape ) { - return lpad( shape.join( ' x ' ), 20, ' ' ); -} - -shapes = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] -]; - -for ( i = 0; i < shapes.length; i++ ) { - sh = shapes[ i ]; - for ( j = 0; j < sh.length; j++ ) { - console.log( shape2string( sh[ j ] ) ); - } - console.log( lpad( '', 20, '-' ) ); - - out = broadcastShapes( sh ); - console.log( shape2string( out )+'\n' ); -} diff --git a/include/stdlib/ndarray/base/broadcast_shapes.h b/include/stdlib/ndarray/base/broadcast_shapes.h deleted file mode 100644 index e23dce1..0000000 --- a/include/stdlib/ndarray/base/broadcast_shapes.h +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#ifndef STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H -#define STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H - -#include - -/* -* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. -*/ -#ifdef __cplusplus -extern "C" { -#endif - -/** -* Broadcasts array shapes to a single shape. -*/ -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H diff --git a/index.js b/index.js new file mode 100644 index 0000000..635432d --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map new file mode 100644 index 0000000..b2b182b --- /dev/null +++ b/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,EAIR,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,EAEN,OAAOR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 0c9817e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Broadcast array shapes to a single shape. -* -* @module @stdlib/ndarray-base-broadcast-shapes -* -* @example -* var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); -* -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -*/ - -// 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 8558e60..0000000 --- a/lib/main.js +++ /dev/null @@ -1,256 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param {Array} shapes - array of shape arrays -* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`) -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [ 8, 0, 1, 6, 1 ], -* [ 8, 8, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -function broadcastShapes( shapes ) { - var ndims; - var out; - var dim; - var sh; - var n1; - var n2; - var d; - var M; - var N; - var i; - var j; - - M = shapes.length; - out = []; - if ( M === 0 ) { - return out; - } - sh = shapes[ 0 ]; - N = sh.length; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M === 1 ) { - // Need to manually copy to output shape, as shapes could be array-like objects... - for ( i = 0; i < N; i++ ) { - out.push( sh[ i ] ); - } - return out; - } - // Determine the maximum dimensionality... - ndims = [ N ]; - for ( i = 1; i < M; i++ ) { - ndims.push( shapes[ i ].length ); - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Initialize the output array... - for ( i = 0; i < N; i++ ) { - out.push( 0 ); - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim === 1 ) { - dim = d; - continue; - } - if ( d === 1 || dim === d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return null; - } - out[ i ] = dim; - i -= 1; - } - return out; -} - - -// EXPORTS // - -module.exports = broadcastShapes; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 890a937..0000000 --- a/manifest.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "options": {}, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [] - } - ] -} diff --git a/package.json b/package.json index 71ded4c..096d386 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,7 @@ "version": "0.0.8", "description": "Broadcast array shapes to a single shape.", "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", - "include": "./include", - "lib": "./lib", - "src": "./src", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "main": "./index.js", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,33 +12,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/types": "^0.0.x", - "@stdlib/utils-library-manifest": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x" - }, - "devDependencies": { - "@stdlib/bench": "^0.0.x", - "@stdlib/string-left-pad": "^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", "stdtypes", @@ -80,9 +27,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" } -} \ No newline at end of file +} diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 35a3654..0000000 --- a/src/main.c +++ /dev/null @@ -1,118 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). -* -* - Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. -* -* @param M number of array shapes -* @param shapes pointer to an array containing shape arrays -* @param ndims array containing the number of dimensions for (i.e., length of) each respective shape array -* @param out pointer to output array -* @return status -* -* @example -* #include "stdlib/ndarray/base/broadcast_shapes.h" -* #include -* -* int64_t N1 = 4; -* int64_t sh1[] = { 8, 1, 6, 1 }; -* -* int64_t N2 = 3; -* int64_t sh2[] = { 7, 1, 5 }; -* -* int64_t ndims[] = { N1, N2 }; -* int64_t *shapes[] = { sh1, sh2 }; -* -* int64_t out[] = { 0, 0, 0, 0 }; -* int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -*/ -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ) { - int64_t dim; - int64_t *sh; - int64_t n1; - int64_t n2; - int64_t d; - int64_t N; - int64_t i; - int64_t j; - - if ( M == 0 ) { - return 0; - } - sh = shapes[ 0 ]; - N = ndims[ 0 ]; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M == 1 ) { - for ( i = 0; i < N; i++ ) { - out[ i ] = sh[ i ]; - } - return 0; - } - // Determine the maximum dimensionality... - for ( i = 1; i < M; i++ ) { - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim == 1 ) { - dim = d; - continue; - } - if ( d == 1 || dim == d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return -1; - } - out[ i ] = dim; - i -= 1; - } - return 0; -} diff --git a/stats_browser.html b/stats_browser.html new file mode 100644 index 0000000..504bf36 --- /dev/null +++ b/stats_browser.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/stats_node.html b/stats_node.html new file mode 100644 index 0000000..fedc035 --- /dev/null +++ b/stats_node.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 63f703c..0000000 --- a/test/test.js +++ /dev/null @@ -1,230 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var broadcastShapes = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastShapes, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] - ]; - - expected = [ - [ 1, 2 ], - [ 3, 4 ], - [ 5, 6, 7 ], - [ 3, 3 ], - [ 3 ], - [ 3, 2 ], - [ 2, 3 ], - [ 1, 2 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty dims)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 0 ], [ 0, 0 ] ], - [ [ 0, 1 ], [ 0, 0 ] ], - [ [ 1, 0 ], [ 0, 1 ] ], - [ [ 1, 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 1, 0 ] ], - [ [ 1, 1 ], [ 0, 1 ] ], - [ [ 0 ], [ 0, 0 ] ], - [ [ 0 ], [ 0, 1 ] ], - [ [ 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 0 ] ], - [ [ 1 ], [ 0, 1 ] ], - [ [ 1 ], [ 1, 0 ] ], - [ [ 1 ], [ 8, 0 ] ], - [ [ 8, 1, 6, 1 ], [ 0, 1, 5 ] ], - [ [ 8, 0, 6, 1 ], [ 1, 5 ] ] - ]; - - expected = [ - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 1, 0 ], - [ 8, 0 ], - [ 8, 0, 6, 5 ], - [ 8, 0, 6, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (no shapes)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [] - ]; - - expected = [ - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty shapes (i.e., zero-dimensional array broadcasting))', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [] ], - [ [], [] ], - [ [], [], [] ], - [ [], [ 0 ] ], - [ [ 0 ], [] ], - [ [], [ 0, 0 ] ], - [ [ 0, 0 ], [] ], - [ [], [ 1, 0 ] ], - [ [], [ 0, 1 ] ], - [ [], [ 3, 3 ] ], - [ [], [ 3, 3 ], [] ] - ]; - - expected = [ - [], - [], - [], - [ 0 ], - [ 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 3, 3 ], - [ 3, 3 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (single shape)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 7 ] ], - [ [ 1, 1 ] ], - [ [ 5, 6, 1 ] ] - ]; - - expected = [ - [ 7 ], - [ 1, 1 ], - [ 5, 6, 1 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function returns `null` if provided incompatible shapes', function test( t ) { - var actual; - var values; - var i; - - values = [ - [ [ 3 ], [ 4 ] ], - [ [ 2, 3 ], [ 2 ] ], - [ [ 3 ], [ 3 ], [ 4 ] ], - [ [ 1, 3, 4 ], [ 2, 3, 3 ] ], - [ [ 1, 2 ], [ 3, 1 ], [ 3, 2 ], [ 10, 5 ] ], - [ [ 2 ], [ 2, 3 ] ], - [ [ 2 ], [ 2 ], [ 2 ], [ 2 ], [ 3 ], [ 3 ], [ 3 ], [ 3 ] ], - [ [ 9, 0, 9 ], [ 0, 9, 0 ] ], - [ [ 9, 9, 9 ], [ 0, 9, 9 ] ], - [ [ 9, 0, 9 ], [ 9, 9, 9 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 0 ] ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.strictEqual( actual, null, 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); From 8897d01cede13126ba706845c91b27bc44453d4c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Oct 2022 03:38:14 +0000 Subject: [PATCH 017/158] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index e004d17..71ded4c 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,8 @@ }, "dependencies": { "@stdlib/types": "^0.0.x", - "@stdlib/utils-library-manifest": "^0.0.x" + "@stdlib/utils-library-manifest": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x" }, "devDependencies": { "@stdlib/bench": "^0.0.x", @@ -84,4 +85,4 @@ "type": "patreon", "url": "https://www.patreon.com/athan" } -} +} \ No newline at end of file From 147656c46686730e0a65ef000fc4fb7d2880a93b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Oct 2022 17:38:34 +0000 Subject: [PATCH 018/158] Remove files --- browser.js | 3 - browser.js.map | 1 - index.js | 3 - index.js.map | 1 - stats_browser.html | 2689 -------------------------------------------- stats_node.html | 2689 -------------------------------------------- 6 files changed, 5386 deletions(-) delete mode 100644 browser.js delete mode 100644 browser.js.map delete mode 100644 index.js delete mode 100644 index.js.map delete mode 100644 stats_browser.html delete mode 100644 stats_node.html diff --git a/browser.js b/browser.js deleted file mode 100644 index 3c259e1..0000000 --- a/browser.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); -//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map deleted file mode 100644 index 1fb93c0..0000000 --- a/browser.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"browser.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,EAIR,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,EAEN,OAAOR"} \ No newline at end of file diff --git a/index.js b/index.js deleted file mode 100644 index 635432d..0000000 --- a/index.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); -//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map deleted file mode 100644 index b2b182b..0000000 --- a/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,EAIR,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,EAEN,OAAOR"} \ No newline at end of file diff --git a/stats_browser.html b/stats_browser.html deleted file mode 100644 index 504bf36..0000000 --- a/stats_browser.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - diff --git a/stats_node.html b/stats_node.html deleted file mode 100644 index fedc035..0000000 --- a/stats_node.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From e5923911649b370dd85b53937edda255d14afc87 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Oct 2022 17:39:19 +0000 Subject: [PATCH 019/158] 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 | 178 +- benchmark/benchmark.js | 112 - benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 152 - branches.md | 53 - browser.js | 3 + browser.js.map | 1 + docs/repl.txt | 39 - docs/types/index.d.ts | 177 -- docs/types/test.ts | 45 - examples/c/Makefile | 146 - examples/c/example.c | 50 - examples/index.js | 54 - .../stdlib/ndarray/base/broadcast_shapes.h | 40 - index.js | 3 + index.js.map | 1 + lib/index.js | 45 - lib/main.js | 256 -- manifest.json | 38 - package.json | 58 +- src/main.c | 118 - stats_browser.html | 2689 +++++++++++++++++ stats_node.html | 2689 +++++++++++++++++ test/test.js | 230 -- 47 files changed, 5424 insertions(+), 4803 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.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 branches.md create mode 100644 browser.js create mode 100644 browser.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/index.d.ts delete mode 100644 docs/types/test.ts delete mode 100644 examples/c/Makefile delete mode 100644 examples/c/example.c delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/broadcast_shapes.h create mode 100644 index.js create mode 100644 index.js.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 manifest.json delete mode 100644 src/main.c create mode 100644 stats_browser.html create mode 100644 stats_node.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 50bde87..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-10-01T01:10:31.203Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 7f004ad..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 8a49110..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 +``` + +If no recognized module system is present, access bundle contents via the global scope: + +```html + ``` #### broadcastShapes( shapes ) @@ -232,9 +240,14 @@ var sh = broadcastShapes( [ sh1, sh2 ] ); -```javascript -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); +```html + + + + + + + + ```
@@ -275,131 +293,7 @@ for ( i = 0; i < shapes.length; i++ ) { -* * * - -
- -## C APIs - - - -
- -
- - - - - -
- -### Usage - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -``` - -#### stdlib_ndarray_broadcast_shapes( M, \*\*shapes, \*ndims, \*out ) - -Broadcasts array shapes to a single shape. - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -int64_t N1 = 4; -int64_t sh1[] = { 8, 1, 6, 1 }; - -int64_t N2 = 3; -int64_t sh2[] = { 7, 1, 5 }; - -int64_t ndims[] = { N1, N2 }; -int64_t *shapes[] = { sh1, sh2 }; - -int64_t out[] = { 0, 0, 0, 0 }; -int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -if ( status != 0 ) { - // Handle error... -} -``` - -The function accepts the following arguments: - -- **M**: `[in] int64_t` number of shape arrays. -- **shapes**: `[in] int64_t**` array of shape arrays (dimensions). -- **ndims**: `[in] int64_t*` number of dimensions for each respective shape array. -- **out**: `[out] int64_t*` output shape array. - -```c -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ); -``` - -If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). - -
- - - - - -
- -### Notes - -- Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. - -
- - - - - -
- -### Examples - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main() { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} -``` - -
- - - -
- diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index fa610dc..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,112 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pkg = require( './../package.json' ).name; -var broadcastShapes = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::two_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ] ], - [ [ 3, 2 ], [ 3, 1 ] ], - [ [ 1, 1 ], [ 2, 2 ] ], - [ [ 1 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::three_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::four_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ], [ 8, 1, 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ], [ 1, 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ], [ 1, 1, 2, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ], [ 1 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ], [ 5, 1, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/c/Makefile b/benchmark/c/Makefile deleted file mode 100644 index 5dc545c..0000000 --- a/benchmark/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := benchmark.out - - -# RULES # - -#/ -# Compiles C source files. -# -# @param {string} SOURCE_FILES - list of C source files -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lpthread -lblas`) -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [C_COMPILER] - C compiler -# @param {string} [CFLAGS] - C compiler flags -# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} SOURCE_FILES - list of C source files -# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {(string|void)} LIBRARIES - list of libraries (e.g., `-lpthread -lblas`) -# @param {(string|void)} LIBPATH - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} CC - C compiler -# @param {string} CFLAGS - C compiler flags -# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled benchmarks. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/benchmark/c/benchmark.c b/benchmark/c/benchmark.c deleted file mode 100644 index be62cd5..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,152 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/** -* Benchmark `broadcast_shapes`. -*/ -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "broadcast-shapes" -#define ITERATIONS 1000000 -#define REPEATS 3 - -/** -* Prints the TAP version. -*/ -void print_version() { - printf( "TAP version 13\n" ); -} - -/** -* Prints the TAP summary. -* -* @param total total number of tests -* @param passing total number of passing tests -*/ -void print_summary( int total, int passing ) { - printf( "#\n" ); - printf( "1..%d\n", total ); // TAP plan - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); -} - -/** -* Prints benchmarks results. -* -* @param elapsed elapsed time in seconds -*/ -void print_results( double elapsed ) { - double rate = (double)ITERATIONS / elapsed; - printf( " ---\n" ); - printf( " iterations: %d\n", ITERATIONS ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", rate ); - printf( " ...\n" ); -} - -/** -* Returns a clock time. -* -* @return clock time -*/ -double tic() { - struct timeval now; - gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; -} - -/** -* Generates a random double on the interval [0,1]. -* -* @return random double -*/ -double rand_double() { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark() { - double elapsed; - int8_t status; - double t; - int i; - - int64_t sh1[] = { 8, 1, 6, 1 }; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { 4, 3 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( out[ 0 ] != 8 ) { - printf( "unexpected result\n" ); - } - if ( out[ 1 ] != 7 ) { - printf( "unexpected result\n" ); - } - if ( out[ 2 ] != 6 ) { - printf( "unexpected result\n" ); - } - if ( out[ 3 ] != 5 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Main execution sequence. -*/ -int main( void ) { - double elapsed; - int i; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - for ( i = 0; i < REPEATS; i++ ) { - printf( "# c::native::%s::two_arrays\n", NAME ); - elapsed = benchmark(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", i+1 ); - } - print_summary( REPEATS, REPEATS ); -} diff --git a/branches.md b/branches.md deleted file mode 100644 index 20fbab5..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes" -click B href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/main" -click C href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production" -click D href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm \ No newline at end of file diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..3c259e1 --- /dev/null +++ b/browser.js @@ -0,0 +1,3 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map new file mode 100644 index 0000000..1fb93c0 --- /dev/null +++ b/browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"browser.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,EAIR,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,EAEN,OAAOR"} \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f1d92f6..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,39 +0,0 @@ - -{{alias}}( shapes ) - Broadcasts array shapes to a single shape. - - Two respective dimensions in two shape arrays are compatible if - - 1. the dimensions are equal. - 2. one dimension is `1`. - - The function returns `null` if provided incompatible shapes (i.e., shapes - which cannot be broadcast with one another). - - Parameters - ---------- - shapes: Array - Array of shape arrays. - - Returns - ------- - out: Array|null - Broadcast shape. - - Examples - -------- - // Compatible shapes: - > var sh1 = [ 8, 1, 6, 1 ]; - > var sh2 = [ 7, 1, 5 ]; - > var sh = {{alias}}( [ sh1, sh2 ] ) - [ 8, 7, 6, 5 ] - - // Incompatible shapes: - > sh1 = [ 3, 2 ]; - > sh1 = [ 2, 3 ]; - > sh = {{alias}}( [ sh1, sh2 ] ) - null - - See Also - -------- - diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts deleted file mode 100644 index f46767d..0000000 --- a/docs/types/index.d.ts +++ /dev/null @@ -1,177 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ArrayLike } from '@stdlib/types/array'; - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param shapes - array shapes -* @returns broadcast shape -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -declare function broadcastShapes( shapes: ArrayLike> ): ArrayLike; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = broadcastShapes; diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 2886539..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 broadcastShapes = require( './index' ); - - -// TESTS // - -// The function returns an array of numbers... -{ - broadcastShapes( [ [ 1, 2 ], [ 2, 2 ] ] ); // $ExpectType ArrayLike -} - -// The compiler throws an error if the function is not provided an array-like object containing array-like objects containing numbers... -{ - broadcastShapes( '5' ); // $ExpectError - broadcastShapes( 5 ); // $ExpectError - broadcastShapes( true ); // $ExpectError - broadcastShapes( false ); // $ExpectError - broadcastShapes( null ); // $ExpectError - broadcastShapes( {} ); // $ExpectError - broadcastShapes( [ '5' ] ); // $ExpectError - broadcastShapes( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - broadcastShapes(); // $ExpectError - broadcastShapes( [ [ 1, 2, 3 ] ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/c/Makefile b/examples/c/Makefile deleted file mode 100644 index 70c91f4..0000000 --- a/examples/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := example.out - - -# RULES # - -#/ -# Compiles source files. -# -# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) -# @param {string} [CFLAGS] - C compiler options -# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) -# @param {string} [SOURCE_FILES] - list of source files -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} CC - C compiler (e.g., `gcc`) -# @param {string} CFLAGS - C compiler options -# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) -# @param {string} SOURCE_FILES - list of source files -# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) -# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled examples. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/examples/c/example.c b/examples/c/example.c deleted file mode 100644 index fae2252..0000000 --- a/examples/c/example.c +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main() { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 28811f9..0000000 --- a/examples/index.js +++ /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. -*/ - -'use strict'; - -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( './../lib' ); - -var shapes; -var out; -var sh; -var i; -var j; - -function shape2string( shape ) { - return lpad( shape.join( ' x ' ), 20, ' ' ); -} - -shapes = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] -]; - -for ( i = 0; i < shapes.length; i++ ) { - sh = shapes[ i ]; - for ( j = 0; j < sh.length; j++ ) { - console.log( shape2string( sh[ j ] ) ); - } - console.log( lpad( '', 20, '-' ) ); - - out = broadcastShapes( sh ); - console.log( shape2string( out )+'\n' ); -} diff --git a/include/stdlib/ndarray/base/broadcast_shapes.h b/include/stdlib/ndarray/base/broadcast_shapes.h deleted file mode 100644 index e23dce1..0000000 --- a/include/stdlib/ndarray/base/broadcast_shapes.h +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#ifndef STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H -#define STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H - -#include - -/* -* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. -*/ -#ifdef __cplusplus -extern "C" { -#endif - -/** -* Broadcasts array shapes to a single shape. -*/ -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H diff --git a/index.js b/index.js new file mode 100644 index 0000000..635432d --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map new file mode 100644 index 0000000..b2b182b --- /dev/null +++ b/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,EAIR,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,EAEN,OAAOR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 0c9817e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Broadcast array shapes to a single shape. -* -* @module @stdlib/ndarray-base-broadcast-shapes -* -* @example -* var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); -* -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -*/ - -// 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 8558e60..0000000 --- a/lib/main.js +++ /dev/null @@ -1,256 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param {Array} shapes - array of shape arrays -* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`) -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [ 8, 0, 1, 6, 1 ], -* [ 8, 8, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -function broadcastShapes( shapes ) { - var ndims; - var out; - var dim; - var sh; - var n1; - var n2; - var d; - var M; - var N; - var i; - var j; - - M = shapes.length; - out = []; - if ( M === 0 ) { - return out; - } - sh = shapes[ 0 ]; - N = sh.length; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M === 1 ) { - // Need to manually copy to output shape, as shapes could be array-like objects... - for ( i = 0; i < N; i++ ) { - out.push( sh[ i ] ); - } - return out; - } - // Determine the maximum dimensionality... - ndims = [ N ]; - for ( i = 1; i < M; i++ ) { - ndims.push( shapes[ i ].length ); - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Initialize the output array... - for ( i = 0; i < N; i++ ) { - out.push( 0 ); - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim === 1 ) { - dim = d; - continue; - } - if ( d === 1 || dim === d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return null; - } - out[ i ] = dim; - i -= 1; - } - return out; -} - - -// EXPORTS // - -module.exports = broadcastShapes; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 890a937..0000000 --- a/manifest.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "options": {}, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [] - } - ] -} diff --git a/package.json b/package.json index 71ded4c..096d386 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,7 @@ "version": "0.0.8", "description": "Broadcast array shapes to a single shape.", "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", - "include": "./include", - "lib": "./lib", - "src": "./src", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "main": "./index.js", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,33 +12,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/types": "^0.0.x", - "@stdlib/utils-library-manifest": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x" - }, - "devDependencies": { - "@stdlib/bench": "^0.0.x", - "@stdlib/string-left-pad": "^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", "stdtypes", @@ -80,9 +27,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" } -} \ No newline at end of file +} diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 35a3654..0000000 --- a/src/main.c +++ /dev/null @@ -1,118 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). -* -* - Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. -* -* @param M number of array shapes -* @param shapes pointer to an array containing shape arrays -* @param ndims array containing the number of dimensions for (i.e., length of) each respective shape array -* @param out pointer to output array -* @return status -* -* @example -* #include "stdlib/ndarray/base/broadcast_shapes.h" -* #include -* -* int64_t N1 = 4; -* int64_t sh1[] = { 8, 1, 6, 1 }; -* -* int64_t N2 = 3; -* int64_t sh2[] = { 7, 1, 5 }; -* -* int64_t ndims[] = { N1, N2 }; -* int64_t *shapes[] = { sh1, sh2 }; -* -* int64_t out[] = { 0, 0, 0, 0 }; -* int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -*/ -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ) { - int64_t dim; - int64_t *sh; - int64_t n1; - int64_t n2; - int64_t d; - int64_t N; - int64_t i; - int64_t j; - - if ( M == 0 ) { - return 0; - } - sh = shapes[ 0 ]; - N = ndims[ 0 ]; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M == 1 ) { - for ( i = 0; i < N; i++ ) { - out[ i ] = sh[ i ]; - } - return 0; - } - // Determine the maximum dimensionality... - for ( i = 1; i < M; i++ ) { - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim == 1 ) { - dim = d; - continue; - } - if ( d == 1 || dim == d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return -1; - } - out[ i ] = dim; - i -= 1; - } - return 0; -} diff --git a/stats_browser.html b/stats_browser.html new file mode 100644 index 0000000..a5bc781 --- /dev/null +++ b/stats_browser.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/stats_node.html b/stats_node.html new file mode 100644 index 0000000..d6d90bb --- /dev/null +++ b/stats_node.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 63f703c..0000000 --- a/test/test.js +++ /dev/null @@ -1,230 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var broadcastShapes = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastShapes, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] - ]; - - expected = [ - [ 1, 2 ], - [ 3, 4 ], - [ 5, 6, 7 ], - [ 3, 3 ], - [ 3 ], - [ 3, 2 ], - [ 2, 3 ], - [ 1, 2 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty dims)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 0 ], [ 0, 0 ] ], - [ [ 0, 1 ], [ 0, 0 ] ], - [ [ 1, 0 ], [ 0, 1 ] ], - [ [ 1, 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 1, 0 ] ], - [ [ 1, 1 ], [ 0, 1 ] ], - [ [ 0 ], [ 0, 0 ] ], - [ [ 0 ], [ 0, 1 ] ], - [ [ 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 0 ] ], - [ [ 1 ], [ 0, 1 ] ], - [ [ 1 ], [ 1, 0 ] ], - [ [ 1 ], [ 8, 0 ] ], - [ [ 8, 1, 6, 1 ], [ 0, 1, 5 ] ], - [ [ 8, 0, 6, 1 ], [ 1, 5 ] ] - ]; - - expected = [ - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 1, 0 ], - [ 8, 0 ], - [ 8, 0, 6, 5 ], - [ 8, 0, 6, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (no shapes)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [] - ]; - - expected = [ - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty shapes (i.e., zero-dimensional array broadcasting))', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [] ], - [ [], [] ], - [ [], [], [] ], - [ [], [ 0 ] ], - [ [ 0 ], [] ], - [ [], [ 0, 0 ] ], - [ [ 0, 0 ], [] ], - [ [], [ 1, 0 ] ], - [ [], [ 0, 1 ] ], - [ [], [ 3, 3 ] ], - [ [], [ 3, 3 ], [] ] - ]; - - expected = [ - [], - [], - [], - [ 0 ], - [ 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 3, 3 ], - [ 3, 3 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (single shape)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 7 ] ], - [ [ 1, 1 ] ], - [ [ 5, 6, 1 ] ] - ]; - - expected = [ - [ 7 ], - [ 1, 1 ], - [ 5, 6, 1 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function returns `null` if provided incompatible shapes', function test( t ) { - var actual; - var values; - var i; - - values = [ - [ [ 3 ], [ 4 ] ], - [ [ 2, 3 ], [ 2 ] ], - [ [ 3 ], [ 3 ], [ 4 ] ], - [ [ 1, 3, 4 ], [ 2, 3, 3 ] ], - [ [ 1, 2 ], [ 3, 1 ], [ 3, 2 ], [ 10, 5 ] ], - [ [ 2 ], [ 2, 3 ] ], - [ [ 2 ], [ 2 ], [ 2 ], [ 2 ], [ 3 ], [ 3 ], [ 3 ], [ 3 ] ], - [ [ 9, 0, 9 ], [ 0, 9, 0 ] ], - [ [ 9, 9, 9 ], [ 0, 9, 9 ] ], - [ [ 9, 0, 9 ], [ 9, 9, 9 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 0 ] ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.strictEqual( actual, null, 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); From 1d4f969e783bfcdc4c7be4b0ce35c6f3fadf300a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Nov 2022 03:24:14 +0000 Subject: [PATCH 020/158] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index e004d17..71ded4c 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,8 @@ }, "dependencies": { "@stdlib/types": "^0.0.x", - "@stdlib/utils-library-manifest": "^0.0.x" + "@stdlib/utils-library-manifest": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x" }, "devDependencies": { "@stdlib/bench": "^0.0.x", @@ -84,4 +85,4 @@ "type": "patreon", "url": "https://www.patreon.com/athan" } -} +} \ No newline at end of file From 292ca64e1fbc9a9da47ecadff180f9b1adbff9eb Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Nov 2022 10:56:24 +0000 Subject: [PATCH 021/158] Remove files --- browser.js | 3 - browser.js.map | 1 - index.js | 3 - index.js.map | 1 - stats_browser.html | 2689 -------------------------------------------- stats_node.html | 2689 -------------------------------------------- 6 files changed, 5386 deletions(-) delete mode 100644 browser.js delete mode 100644 browser.js.map delete mode 100644 index.js delete mode 100644 index.js.map delete mode 100644 stats_browser.html delete mode 100644 stats_node.html diff --git a/browser.js b/browser.js deleted file mode 100644 index 3c259e1..0000000 --- a/browser.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); -//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map deleted file mode 100644 index 1fb93c0..0000000 --- a/browser.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"browser.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,EAIR,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,EAEN,OAAOR"} \ No newline at end of file diff --git a/index.js b/index.js deleted file mode 100644 index 635432d..0000000 --- a/index.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); -//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map deleted file mode 100644 index b2b182b..0000000 --- a/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,EAIR,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,EAEN,OAAOR"} \ No newline at end of file diff --git a/stats_browser.html b/stats_browser.html deleted file mode 100644 index a5bc781..0000000 --- a/stats_browser.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - diff --git a/stats_node.html b/stats_node.html deleted file mode 100644 index d6d90bb..0000000 --- a/stats_node.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 09cb9b1110d38ea06c63127c173d5ea078b90179 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Nov 2022 10:57:12 +0000 Subject: [PATCH 022/158] 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 | 178 +- benchmark/benchmark.js | 112 - benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 152 - branches.md | 53 - browser.js | 3 + browser.js.map | 1 + docs/repl.txt | 39 - docs/types/index.d.ts | 177 - docs/types/test.ts | 45 - examples/c/Makefile | 146 - examples/c/example.c | 50 - examples/index.js | 54 - .../stdlib/ndarray/base/broadcast_shapes.h | 40 - index.js | 3 + index.js.map | 1 + lib/index.js | 45 - lib/main.js | 256 -- manifest.json | 38 - package.json | 58 +- src/main.c | 118 - stats_browser.html | 4044 +++++++++++++++++ stats_node.html | 4044 +++++++++++++++++ test/test.js | 230 - 47 files changed, 8134 insertions(+), 4803 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.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 branches.md create mode 100644 browser.js create mode 100644 browser.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/index.d.ts delete mode 100644 docs/types/test.ts delete mode 100644 examples/c/Makefile delete mode 100644 examples/c/example.c delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/broadcast_shapes.h create mode 100644 index.js create mode 100644 index.js.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 manifest.json delete mode 100644 src/main.c create mode 100644 stats_browser.html create mode 100644 stats_node.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 41c100b..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-11-01T00:56:56.909Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 7f004ad..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 8a49110..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 0bff0a0..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 12 * * 5' - - # 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 +``` + +If no recognized module system is present, access bundle contents via the global scope: + +```html + ``` #### broadcastShapes( shapes ) @@ -232,9 +240,14 @@ var sh = broadcastShapes( [ sh1, sh2 ] ); -```javascript -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); +```html + + + + + + + + ```
@@ -275,131 +293,7 @@ for ( i = 0; i < shapes.length; i++ ) { -* * * - -
- -## C APIs - - - -
- -
- - - - - -
- -### Usage - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -``` - -#### stdlib_ndarray_broadcast_shapes( M, \*\*shapes, \*ndims, \*out ) - -Broadcasts array shapes to a single shape. - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -int64_t N1 = 4; -int64_t sh1[] = { 8, 1, 6, 1 }; - -int64_t N2 = 3; -int64_t sh2[] = { 7, 1, 5 }; - -int64_t ndims[] = { N1, N2 }; -int64_t *shapes[] = { sh1, sh2 }; - -int64_t out[] = { 0, 0, 0, 0 }; -int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -if ( status != 0 ) { - // Handle error... -} -``` - -The function accepts the following arguments: - -- **M**: `[in] int64_t` number of shape arrays. -- **shapes**: `[in] int64_t**` array of shape arrays (dimensions). -- **ndims**: `[in] int64_t*` number of dimensions for each respective shape array. -- **out**: `[out] int64_t*` output shape array. - -```c -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ); -``` - -If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). - -
- - - - - -
- -### Notes - -- Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. - -
- - - - - -
- -### Examples - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main() { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} -``` - -
- - - -
- diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index fa610dc..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,112 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pkg = require( './../package.json' ).name; -var broadcastShapes = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::two_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ] ], - [ [ 3, 2 ], [ 3, 1 ] ], - [ [ 1, 1 ], [ 2, 2 ] ], - [ [ 1 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::three_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::four_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ], [ 8, 1, 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ], [ 1, 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ], [ 1, 1, 2, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ], [ 1 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ], [ 5, 1, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/c/Makefile b/benchmark/c/Makefile deleted file mode 100644 index 5dc545c..0000000 --- a/benchmark/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := benchmark.out - - -# RULES # - -#/ -# Compiles C source files. -# -# @param {string} SOURCE_FILES - list of C source files -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lpthread -lblas`) -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [C_COMPILER] - C compiler -# @param {string} [CFLAGS] - C compiler flags -# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} SOURCE_FILES - list of C source files -# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {(string|void)} LIBRARIES - list of libraries (e.g., `-lpthread -lblas`) -# @param {(string|void)} LIBPATH - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} CC - C compiler -# @param {string} CFLAGS - C compiler flags -# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled benchmarks. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/benchmark/c/benchmark.c b/benchmark/c/benchmark.c deleted file mode 100644 index be62cd5..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,152 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/** -* Benchmark `broadcast_shapes`. -*/ -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "broadcast-shapes" -#define ITERATIONS 1000000 -#define REPEATS 3 - -/** -* Prints the TAP version. -*/ -void print_version() { - printf( "TAP version 13\n" ); -} - -/** -* Prints the TAP summary. -* -* @param total total number of tests -* @param passing total number of passing tests -*/ -void print_summary( int total, int passing ) { - printf( "#\n" ); - printf( "1..%d\n", total ); // TAP plan - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); -} - -/** -* Prints benchmarks results. -* -* @param elapsed elapsed time in seconds -*/ -void print_results( double elapsed ) { - double rate = (double)ITERATIONS / elapsed; - printf( " ---\n" ); - printf( " iterations: %d\n", ITERATIONS ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", rate ); - printf( " ...\n" ); -} - -/** -* Returns a clock time. -* -* @return clock time -*/ -double tic() { - struct timeval now; - gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; -} - -/** -* Generates a random double on the interval [0,1]. -* -* @return random double -*/ -double rand_double() { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark() { - double elapsed; - int8_t status; - double t; - int i; - - int64_t sh1[] = { 8, 1, 6, 1 }; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { 4, 3 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( out[ 0 ] != 8 ) { - printf( "unexpected result\n" ); - } - if ( out[ 1 ] != 7 ) { - printf( "unexpected result\n" ); - } - if ( out[ 2 ] != 6 ) { - printf( "unexpected result\n" ); - } - if ( out[ 3 ] != 5 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Main execution sequence. -*/ -int main( void ) { - double elapsed; - int i; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - for ( i = 0; i < REPEATS; i++ ) { - printf( "# c::native::%s::two_arrays\n", NAME ); - elapsed = benchmark(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", i+1 ); - } - print_summary( REPEATS, REPEATS ); -} diff --git a/branches.md b/branches.md deleted file mode 100644 index 20fbab5..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes" -click B href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/main" -click C href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production" -click D href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm \ No newline at end of file diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..3c259e1 --- /dev/null +++ b/browser.js @@ -0,0 +1,3 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map new file mode 100644 index 0000000..aa4b2bb --- /dev/null +++ b/browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"browser.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f1d92f6..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,39 +0,0 @@ - -{{alias}}( shapes ) - Broadcasts array shapes to a single shape. - - Two respective dimensions in two shape arrays are compatible if - - 1. the dimensions are equal. - 2. one dimension is `1`. - - The function returns `null` if provided incompatible shapes (i.e., shapes - which cannot be broadcast with one another). - - Parameters - ---------- - shapes: Array - Array of shape arrays. - - Returns - ------- - out: Array|null - Broadcast shape. - - Examples - -------- - // Compatible shapes: - > var sh1 = [ 8, 1, 6, 1 ]; - > var sh2 = [ 7, 1, 5 ]; - > var sh = {{alias}}( [ sh1, sh2 ] ) - [ 8, 7, 6, 5 ] - - // Incompatible shapes: - > sh1 = [ 3, 2 ]; - > sh1 = [ 2, 3 ]; - > sh = {{alias}}( [ sh1, sh2 ] ) - null - - See Also - -------- - diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts deleted file mode 100644 index f46767d..0000000 --- a/docs/types/index.d.ts +++ /dev/null @@ -1,177 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ArrayLike } from '@stdlib/types/array'; - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param shapes - array shapes -* @returns broadcast shape -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -declare function broadcastShapes( shapes: ArrayLike> ): ArrayLike; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = broadcastShapes; diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 2886539..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 broadcastShapes = require( './index' ); - - -// TESTS // - -// The function returns an array of numbers... -{ - broadcastShapes( [ [ 1, 2 ], [ 2, 2 ] ] ); // $ExpectType ArrayLike -} - -// The compiler throws an error if the function is not provided an array-like object containing array-like objects containing numbers... -{ - broadcastShapes( '5' ); // $ExpectError - broadcastShapes( 5 ); // $ExpectError - broadcastShapes( true ); // $ExpectError - broadcastShapes( false ); // $ExpectError - broadcastShapes( null ); // $ExpectError - broadcastShapes( {} ); // $ExpectError - broadcastShapes( [ '5' ] ); // $ExpectError - broadcastShapes( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - broadcastShapes(); // $ExpectError - broadcastShapes( [ [ 1, 2, 3 ] ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/c/Makefile b/examples/c/Makefile deleted file mode 100644 index 70c91f4..0000000 --- a/examples/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := example.out - - -# RULES # - -#/ -# Compiles source files. -# -# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) -# @param {string} [CFLAGS] - C compiler options -# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) -# @param {string} [SOURCE_FILES] - list of source files -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} CC - C compiler (e.g., `gcc`) -# @param {string} CFLAGS - C compiler options -# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) -# @param {string} SOURCE_FILES - list of source files -# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) -# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled examples. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/examples/c/example.c b/examples/c/example.c deleted file mode 100644 index fae2252..0000000 --- a/examples/c/example.c +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main() { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 28811f9..0000000 --- a/examples/index.js +++ /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. -*/ - -'use strict'; - -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( './../lib' ); - -var shapes; -var out; -var sh; -var i; -var j; - -function shape2string( shape ) { - return lpad( shape.join( ' x ' ), 20, ' ' ); -} - -shapes = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] -]; - -for ( i = 0; i < shapes.length; i++ ) { - sh = shapes[ i ]; - for ( j = 0; j < sh.length; j++ ) { - console.log( shape2string( sh[ j ] ) ); - } - console.log( lpad( '', 20, '-' ) ); - - out = broadcastShapes( sh ); - console.log( shape2string( out )+'\n' ); -} diff --git a/include/stdlib/ndarray/base/broadcast_shapes.h b/include/stdlib/ndarray/base/broadcast_shapes.h deleted file mode 100644 index e23dce1..0000000 --- a/include/stdlib/ndarray/base/broadcast_shapes.h +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#ifndef STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H -#define STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H - -#include - -/* -* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. -*/ -#ifdef __cplusplus -extern "C" { -#endif - -/** -* Broadcasts array shapes to a single shape. -*/ -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H diff --git a/index.js b/index.js new file mode 100644 index 0000000..635432d --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map new file mode 100644 index 0000000..0c02c0f --- /dev/null +++ b/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 0c9817e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Broadcast array shapes to a single shape. -* -* @module @stdlib/ndarray-base-broadcast-shapes -* -* @example -* var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); -* -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -*/ - -// 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 8558e60..0000000 --- a/lib/main.js +++ /dev/null @@ -1,256 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param {Array} shapes - array of shape arrays -* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`) -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [ 8, 0, 1, 6, 1 ], -* [ 8, 8, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -function broadcastShapes( shapes ) { - var ndims; - var out; - var dim; - var sh; - var n1; - var n2; - var d; - var M; - var N; - var i; - var j; - - M = shapes.length; - out = []; - if ( M === 0 ) { - return out; - } - sh = shapes[ 0 ]; - N = sh.length; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M === 1 ) { - // Need to manually copy to output shape, as shapes could be array-like objects... - for ( i = 0; i < N; i++ ) { - out.push( sh[ i ] ); - } - return out; - } - // Determine the maximum dimensionality... - ndims = [ N ]; - for ( i = 1; i < M; i++ ) { - ndims.push( shapes[ i ].length ); - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Initialize the output array... - for ( i = 0; i < N; i++ ) { - out.push( 0 ); - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim === 1 ) { - dim = d; - continue; - } - if ( d === 1 || dim === d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return null; - } - out[ i ] = dim; - i -= 1; - } - return out; -} - - -// EXPORTS // - -module.exports = broadcastShapes; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 890a937..0000000 --- a/manifest.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "options": {}, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [] - } - ] -} diff --git a/package.json b/package.json index 71ded4c..096d386 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,7 @@ "version": "0.0.8", "description": "Broadcast array shapes to a single shape.", "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", - "include": "./include", - "lib": "./lib", - "src": "./src", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "main": "./index.js", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,33 +12,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/types": "^0.0.x", - "@stdlib/utils-library-manifest": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x" - }, - "devDependencies": { - "@stdlib/bench": "^0.0.x", - "@stdlib/string-left-pad": "^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", "stdtypes", @@ -80,9 +27,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" } -} \ No newline at end of file +} diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 35a3654..0000000 --- a/src/main.c +++ /dev/null @@ -1,118 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). -* -* - Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. -* -* @param M number of array shapes -* @param shapes pointer to an array containing shape arrays -* @param ndims array containing the number of dimensions for (i.e., length of) each respective shape array -* @param out pointer to output array -* @return status -* -* @example -* #include "stdlib/ndarray/base/broadcast_shapes.h" -* #include -* -* int64_t N1 = 4; -* int64_t sh1[] = { 8, 1, 6, 1 }; -* -* int64_t N2 = 3; -* int64_t sh2[] = { 7, 1, 5 }; -* -* int64_t ndims[] = { N1, N2 }; -* int64_t *shapes[] = { sh1, sh2 }; -* -* int64_t out[] = { 0, 0, 0, 0 }; -* int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -*/ -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ) { - int64_t dim; - int64_t *sh; - int64_t n1; - int64_t n2; - int64_t d; - int64_t N; - int64_t i; - int64_t j; - - if ( M == 0 ) { - return 0; - } - sh = shapes[ 0 ]; - N = ndims[ 0 ]; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M == 1 ) { - for ( i = 0; i < N; i++ ) { - out[ i ] = sh[ i ]; - } - return 0; - } - // Determine the maximum dimensionality... - for ( i = 1; i < M; i++ ) { - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim == 1 ) { - dim = d; - continue; - } - if ( d == 1 || dim == d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return -1; - } - out[ i ] = dim; - i -= 1; - } - return 0; -} diff --git a/stats_browser.html b/stats_browser.html new file mode 100644 index 0000000..8be3975 --- /dev/null +++ b/stats_browser.html @@ -0,0 +1,4044 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/stats_node.html b/stats_node.html new file mode 100644 index 0000000..2e60df6 --- /dev/null +++ b/stats_node.html @@ -0,0 +1,4044 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 63f703c..0000000 --- a/test/test.js +++ /dev/null @@ -1,230 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var broadcastShapes = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastShapes, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] - ]; - - expected = [ - [ 1, 2 ], - [ 3, 4 ], - [ 5, 6, 7 ], - [ 3, 3 ], - [ 3 ], - [ 3, 2 ], - [ 2, 3 ], - [ 1, 2 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty dims)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 0 ], [ 0, 0 ] ], - [ [ 0, 1 ], [ 0, 0 ] ], - [ [ 1, 0 ], [ 0, 1 ] ], - [ [ 1, 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 1, 0 ] ], - [ [ 1, 1 ], [ 0, 1 ] ], - [ [ 0 ], [ 0, 0 ] ], - [ [ 0 ], [ 0, 1 ] ], - [ [ 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 0 ] ], - [ [ 1 ], [ 0, 1 ] ], - [ [ 1 ], [ 1, 0 ] ], - [ [ 1 ], [ 8, 0 ] ], - [ [ 8, 1, 6, 1 ], [ 0, 1, 5 ] ], - [ [ 8, 0, 6, 1 ], [ 1, 5 ] ] - ]; - - expected = [ - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 1, 0 ], - [ 8, 0 ], - [ 8, 0, 6, 5 ], - [ 8, 0, 6, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (no shapes)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [] - ]; - - expected = [ - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty shapes (i.e., zero-dimensional array broadcasting))', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [] ], - [ [], [] ], - [ [], [], [] ], - [ [], [ 0 ] ], - [ [ 0 ], [] ], - [ [], [ 0, 0 ] ], - [ [ 0, 0 ], [] ], - [ [], [ 1, 0 ] ], - [ [], [ 0, 1 ] ], - [ [], [ 3, 3 ] ], - [ [], [ 3, 3 ], [] ] - ]; - - expected = [ - [], - [], - [], - [ 0 ], - [ 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 3, 3 ], - [ 3, 3 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (single shape)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 7 ] ], - [ [ 1, 1 ] ], - [ [ 5, 6, 1 ] ] - ]; - - expected = [ - [ 7 ], - [ 1, 1 ], - [ 5, 6, 1 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function returns `null` if provided incompatible shapes', function test( t ) { - var actual; - var values; - var i; - - values = [ - [ [ 3 ], [ 4 ] ], - [ [ 2, 3 ], [ 2 ] ], - [ [ 3 ], [ 3 ], [ 4 ] ], - [ [ 1, 3, 4 ], [ 2, 3, 3 ] ], - [ [ 1, 2 ], [ 3, 1 ], [ 3, 2 ], [ 10, 5 ] ], - [ [ 2 ], [ 2, 3 ] ], - [ [ 2 ], [ 2 ], [ 2 ], [ 2 ], [ 3 ], [ 3 ], [ 3 ], [ 3 ] ], - [ [ 9, 0, 9 ], [ 0, 9, 0 ] ], - [ [ 9, 9, 9 ], [ 0, 9, 9 ] ], - [ [ 9, 0, 9 ], [ 9, 9, 9 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 0 ] ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.strictEqual( actual, null, 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); From 91de7045bf12a4c6d57166ed7e97770af0795f81 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 3 Nov 2022 23:38:31 +0000 Subject: [PATCH 023/158] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index e004d17..71ded4c 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,8 @@ }, "dependencies": { "@stdlib/types": "^0.0.x", - "@stdlib/utils-library-manifest": "^0.0.x" + "@stdlib/utils-library-manifest": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x" }, "devDependencies": { "@stdlib/bench": "^0.0.x", @@ -84,4 +85,4 @@ "type": "patreon", "url": "https://www.patreon.com/athan" } -} +} \ No newline at end of file From 5ab645c9cfdc53f051826f67edbb10f021603345 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 4 Nov 2022 06:45:59 +0000 Subject: [PATCH 024/158] Remove files --- browser.js | 3 - browser.js.map | 1 - index.js | 3 - index.js.map | 1 - stats_browser.html | 4044 -------------------------------------------- stats_node.html | 4044 -------------------------------------------- 6 files changed, 8096 deletions(-) delete mode 100644 browser.js delete mode 100644 browser.js.map delete mode 100644 index.js delete mode 100644 index.js.map delete mode 100644 stats_browser.html delete mode 100644 stats_node.html diff --git a/browser.js b/browser.js deleted file mode 100644 index 3c259e1..0000000 --- a/browser.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); -//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map deleted file mode 100644 index aa4b2bb..0000000 --- a/browser.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"browser.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/index.js b/index.js deleted file mode 100644 index 635432d..0000000 --- a/index.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); -//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map deleted file mode 100644 index 0c02c0f..0000000 --- a/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/stats_browser.html b/stats_browser.html deleted file mode 100644 index 8be3975..0000000 --- a/stats_browser.html +++ /dev/null @@ -1,4044 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - diff --git a/stats_node.html b/stats_node.html deleted file mode 100644 index 2e60df6..0000000 --- a/stats_node.html +++ /dev/null @@ -1,4044 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 5b2ec6fd740823376059451bf7a522a4b0a79918 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 4 Nov 2022 06:46:43 +0000 Subject: [PATCH 025/158] 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 | 178 +- benchmark/benchmark.js | 112 - benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 152 - branches.md | 53 - browser.js | 3 + browser.js.map | 1 + docs/repl.txt | 39 - docs/types/index.d.ts | 177 - docs/types/test.ts | 45 - examples/c/Makefile | 146 - examples/c/example.c | 50 - examples/index.js | 54 - .../stdlib/ndarray/base/broadcast_shapes.h | 40 - index.js | 3 + index.js.map | 1 + lib/index.js | 45 - lib/main.js | 256 -- manifest.json | 38 - package.json | 58 +- src/main.c | 118 - stats_browser.html | 4044 +++++++++++++++++ stats_node.html | 4044 +++++++++++++++++ test/test.js | 230 - 47 files changed, 8134 insertions(+), 4824 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.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 branches.md create mode 100644 browser.js create mode 100644 browser.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/index.d.ts delete mode 100644 docs/types/test.ts delete mode 100644 examples/c/Makefile delete mode 100644 examples/c/example.c delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/broadcast_shapes.h create mode 100644 index.js create mode 100644 index.js.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 manifest.json delete mode 100644 src/main.c create mode 100644 stats_browser.html create mode 100644 stats_node.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 61fdbd0..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-11-03T21:08:47.179Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 7f004ad..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 8a49110..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 0bff0a0..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 12 * * 5' - - # 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 +``` + +If no recognized module system is present, access bundle contents via the global scope: + +```html + ``` #### broadcastShapes( shapes ) @@ -232,9 +240,14 @@ var sh = broadcastShapes( [ sh1, sh2 ] ); -```javascript -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); +```html + + + + + + + + ```
@@ -275,131 +293,7 @@ for ( i = 0; i < shapes.length; i++ ) { -* * * - -
- -## C APIs - - - -
- -
- - - - - -
- -### Usage - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -``` - -#### stdlib_ndarray_broadcast_shapes( M, \*\*shapes, \*ndims, \*out ) - -Broadcasts array shapes to a single shape. - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -int64_t N1 = 4; -int64_t sh1[] = { 8, 1, 6, 1 }; - -int64_t N2 = 3; -int64_t sh2[] = { 7, 1, 5 }; - -int64_t ndims[] = { N1, N2 }; -int64_t *shapes[] = { sh1, sh2 }; - -int64_t out[] = { 0, 0, 0, 0 }; -int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -if ( status != 0 ) { - // Handle error... -} -``` - -The function accepts the following arguments: - -- **M**: `[in] int64_t` number of shape arrays. -- **shapes**: `[in] int64_t**` array of shape arrays (dimensions). -- **ndims**: `[in] int64_t*` number of dimensions for each respective shape array. -- **out**: `[out] int64_t*` output shape array. - -```c -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ); -``` - -If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). - -
- - - - - -
- -### Notes - -- Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. - -
- - - - - -
- -### Examples - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main() { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} -``` - -
- - - -
- diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index fa610dc..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,112 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pkg = require( './../package.json' ).name; -var broadcastShapes = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::two_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ] ], - [ [ 3, 2 ], [ 3, 1 ] ], - [ [ 1, 1 ], [ 2, 2 ] ], - [ [ 1 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::three_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::four_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ], [ 8, 1, 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ], [ 1, 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ], [ 1, 1, 2, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ], [ 1 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ], [ 5, 1, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/c/Makefile b/benchmark/c/Makefile deleted file mode 100644 index 5dc545c..0000000 --- a/benchmark/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := benchmark.out - - -# RULES # - -#/ -# Compiles C source files. -# -# @param {string} SOURCE_FILES - list of C source files -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lpthread -lblas`) -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [C_COMPILER] - C compiler -# @param {string} [CFLAGS] - C compiler flags -# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} SOURCE_FILES - list of C source files -# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {(string|void)} LIBRARIES - list of libraries (e.g., `-lpthread -lblas`) -# @param {(string|void)} LIBPATH - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} CC - C compiler -# @param {string} CFLAGS - C compiler flags -# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled benchmarks. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/benchmark/c/benchmark.c b/benchmark/c/benchmark.c deleted file mode 100644 index be62cd5..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,152 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/** -* Benchmark `broadcast_shapes`. -*/ -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "broadcast-shapes" -#define ITERATIONS 1000000 -#define REPEATS 3 - -/** -* Prints the TAP version. -*/ -void print_version() { - printf( "TAP version 13\n" ); -} - -/** -* Prints the TAP summary. -* -* @param total total number of tests -* @param passing total number of passing tests -*/ -void print_summary( int total, int passing ) { - printf( "#\n" ); - printf( "1..%d\n", total ); // TAP plan - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); -} - -/** -* Prints benchmarks results. -* -* @param elapsed elapsed time in seconds -*/ -void print_results( double elapsed ) { - double rate = (double)ITERATIONS / elapsed; - printf( " ---\n" ); - printf( " iterations: %d\n", ITERATIONS ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", rate ); - printf( " ...\n" ); -} - -/** -* Returns a clock time. -* -* @return clock time -*/ -double tic() { - struct timeval now; - gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; -} - -/** -* Generates a random double on the interval [0,1]. -* -* @return random double -*/ -double rand_double() { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark() { - double elapsed; - int8_t status; - double t; - int i; - - int64_t sh1[] = { 8, 1, 6, 1 }; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { 4, 3 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( out[ 0 ] != 8 ) { - printf( "unexpected result\n" ); - } - if ( out[ 1 ] != 7 ) { - printf( "unexpected result\n" ); - } - if ( out[ 2 ] != 6 ) { - printf( "unexpected result\n" ); - } - if ( out[ 3 ] != 5 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Main execution sequence. -*/ -int main( void ) { - double elapsed; - int i; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - for ( i = 0; i < REPEATS; i++ ) { - printf( "# c::native::%s::two_arrays\n", NAME ); - elapsed = benchmark(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", i+1 ); - } - print_summary( REPEATS, REPEATS ); -} diff --git a/branches.md b/branches.md deleted file mode 100644 index 20fbab5..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes" -click B href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/main" -click C href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production" -click D href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm \ No newline at end of file diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..3c259e1 --- /dev/null +++ b/browser.js @@ -0,0 +1,3 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map new file mode 100644 index 0000000..aa4b2bb --- /dev/null +++ b/browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"browser.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f1d92f6..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,39 +0,0 @@ - -{{alias}}( shapes ) - Broadcasts array shapes to a single shape. - - Two respective dimensions in two shape arrays are compatible if - - 1. the dimensions are equal. - 2. one dimension is `1`. - - The function returns `null` if provided incompatible shapes (i.e., shapes - which cannot be broadcast with one another). - - Parameters - ---------- - shapes: Array - Array of shape arrays. - - Returns - ------- - out: Array|null - Broadcast shape. - - Examples - -------- - // Compatible shapes: - > var sh1 = [ 8, 1, 6, 1 ]; - > var sh2 = [ 7, 1, 5 ]; - > var sh = {{alias}}( [ sh1, sh2 ] ) - [ 8, 7, 6, 5 ] - - // Incompatible shapes: - > sh1 = [ 3, 2 ]; - > sh1 = [ 2, 3 ]; - > sh = {{alias}}( [ sh1, sh2 ] ) - null - - See Also - -------- - diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts deleted file mode 100644 index f46767d..0000000 --- a/docs/types/index.d.ts +++ /dev/null @@ -1,177 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ArrayLike } from '@stdlib/types/array'; - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param shapes - array shapes -* @returns broadcast shape -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -declare function broadcastShapes( shapes: ArrayLike> ): ArrayLike; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = broadcastShapes; diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 2886539..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 broadcastShapes = require( './index' ); - - -// TESTS // - -// The function returns an array of numbers... -{ - broadcastShapes( [ [ 1, 2 ], [ 2, 2 ] ] ); // $ExpectType ArrayLike -} - -// The compiler throws an error if the function is not provided an array-like object containing array-like objects containing numbers... -{ - broadcastShapes( '5' ); // $ExpectError - broadcastShapes( 5 ); // $ExpectError - broadcastShapes( true ); // $ExpectError - broadcastShapes( false ); // $ExpectError - broadcastShapes( null ); // $ExpectError - broadcastShapes( {} ); // $ExpectError - broadcastShapes( [ '5' ] ); // $ExpectError - broadcastShapes( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - broadcastShapes(); // $ExpectError - broadcastShapes( [ [ 1, 2, 3 ] ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/c/Makefile b/examples/c/Makefile deleted file mode 100644 index 70c91f4..0000000 --- a/examples/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := example.out - - -# RULES # - -#/ -# Compiles source files. -# -# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) -# @param {string} [CFLAGS] - C compiler options -# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) -# @param {string} [SOURCE_FILES] - list of source files -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} CC - C compiler (e.g., `gcc`) -# @param {string} CFLAGS - C compiler options -# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) -# @param {string} SOURCE_FILES - list of source files -# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) -# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled examples. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/examples/c/example.c b/examples/c/example.c deleted file mode 100644 index fae2252..0000000 --- a/examples/c/example.c +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main() { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 28811f9..0000000 --- a/examples/index.js +++ /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. -*/ - -'use strict'; - -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( './../lib' ); - -var shapes; -var out; -var sh; -var i; -var j; - -function shape2string( shape ) { - return lpad( shape.join( ' x ' ), 20, ' ' ); -} - -shapes = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] -]; - -for ( i = 0; i < shapes.length; i++ ) { - sh = shapes[ i ]; - for ( j = 0; j < sh.length; j++ ) { - console.log( shape2string( sh[ j ] ) ); - } - console.log( lpad( '', 20, '-' ) ); - - out = broadcastShapes( sh ); - console.log( shape2string( out )+'\n' ); -} diff --git a/include/stdlib/ndarray/base/broadcast_shapes.h b/include/stdlib/ndarray/base/broadcast_shapes.h deleted file mode 100644 index e23dce1..0000000 --- a/include/stdlib/ndarray/base/broadcast_shapes.h +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#ifndef STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H -#define STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H - -#include - -/* -* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. -*/ -#ifdef __cplusplus -extern "C" { -#endif - -/** -* Broadcasts array shapes to a single shape. -*/ -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H diff --git a/index.js b/index.js new file mode 100644 index 0000000..635432d --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map new file mode 100644 index 0000000..0c02c0f --- /dev/null +++ b/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 0c9817e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Broadcast array shapes to a single shape. -* -* @module @stdlib/ndarray-base-broadcast-shapes -* -* @example -* var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); -* -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -*/ - -// 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 8558e60..0000000 --- a/lib/main.js +++ /dev/null @@ -1,256 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param {Array} shapes - array of shape arrays -* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`) -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [ 8, 0, 1, 6, 1 ], -* [ 8, 8, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -function broadcastShapes( shapes ) { - var ndims; - var out; - var dim; - var sh; - var n1; - var n2; - var d; - var M; - var N; - var i; - var j; - - M = shapes.length; - out = []; - if ( M === 0 ) { - return out; - } - sh = shapes[ 0 ]; - N = sh.length; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M === 1 ) { - // Need to manually copy to output shape, as shapes could be array-like objects... - for ( i = 0; i < N; i++ ) { - out.push( sh[ i ] ); - } - return out; - } - // Determine the maximum dimensionality... - ndims = [ N ]; - for ( i = 1; i < M; i++ ) { - ndims.push( shapes[ i ].length ); - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Initialize the output array... - for ( i = 0; i < N; i++ ) { - out.push( 0 ); - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim === 1 ) { - dim = d; - continue; - } - if ( d === 1 || dim === d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return null; - } - out[ i ] = dim; - i -= 1; - } - return out; -} - - -// EXPORTS // - -module.exports = broadcastShapes; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 890a937..0000000 --- a/manifest.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "options": {}, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [] - } - ] -} diff --git a/package.json b/package.json index 71ded4c..096d386 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,7 @@ "version": "0.0.8", "description": "Broadcast array shapes to a single shape.", "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", - "include": "./include", - "lib": "./lib", - "src": "./src", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "main": "./index.js", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,33 +12,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/types": "^0.0.x", - "@stdlib/utils-library-manifest": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x" - }, - "devDependencies": { - "@stdlib/bench": "^0.0.x", - "@stdlib/string-left-pad": "^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", "stdtypes", @@ -80,9 +27,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" } -} \ No newline at end of file +} diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 35a3654..0000000 --- a/src/main.c +++ /dev/null @@ -1,118 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). -* -* - Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. -* -* @param M number of array shapes -* @param shapes pointer to an array containing shape arrays -* @param ndims array containing the number of dimensions for (i.e., length of) each respective shape array -* @param out pointer to output array -* @return status -* -* @example -* #include "stdlib/ndarray/base/broadcast_shapes.h" -* #include -* -* int64_t N1 = 4; -* int64_t sh1[] = { 8, 1, 6, 1 }; -* -* int64_t N2 = 3; -* int64_t sh2[] = { 7, 1, 5 }; -* -* int64_t ndims[] = { N1, N2 }; -* int64_t *shapes[] = { sh1, sh2 }; -* -* int64_t out[] = { 0, 0, 0, 0 }; -* int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -*/ -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ) { - int64_t dim; - int64_t *sh; - int64_t n1; - int64_t n2; - int64_t d; - int64_t N; - int64_t i; - int64_t j; - - if ( M == 0 ) { - return 0; - } - sh = shapes[ 0 ]; - N = ndims[ 0 ]; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M == 1 ) { - for ( i = 0; i < N; i++ ) { - out[ i ] = sh[ i ]; - } - return 0; - } - // Determine the maximum dimensionality... - for ( i = 1; i < M; i++ ) { - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim == 1 ) { - dim = d; - continue; - } - if ( d == 1 || dim == d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return -1; - } - out[ i ] = dim; - i -= 1; - } - return 0; -} diff --git a/stats_browser.html b/stats_browser.html new file mode 100644 index 0000000..7284dc8 --- /dev/null +++ b/stats_browser.html @@ -0,0 +1,4044 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/stats_node.html b/stats_node.html new file mode 100644 index 0000000..ecb9362 --- /dev/null +++ b/stats_node.html @@ -0,0 +1,4044 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 63f703c..0000000 --- a/test/test.js +++ /dev/null @@ -1,230 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var broadcastShapes = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastShapes, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] - ]; - - expected = [ - [ 1, 2 ], - [ 3, 4 ], - [ 5, 6, 7 ], - [ 3, 3 ], - [ 3 ], - [ 3, 2 ], - [ 2, 3 ], - [ 1, 2 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty dims)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 0 ], [ 0, 0 ] ], - [ [ 0, 1 ], [ 0, 0 ] ], - [ [ 1, 0 ], [ 0, 1 ] ], - [ [ 1, 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 1, 0 ] ], - [ [ 1, 1 ], [ 0, 1 ] ], - [ [ 0 ], [ 0, 0 ] ], - [ [ 0 ], [ 0, 1 ] ], - [ [ 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 0 ] ], - [ [ 1 ], [ 0, 1 ] ], - [ [ 1 ], [ 1, 0 ] ], - [ [ 1 ], [ 8, 0 ] ], - [ [ 8, 1, 6, 1 ], [ 0, 1, 5 ] ], - [ [ 8, 0, 6, 1 ], [ 1, 5 ] ] - ]; - - expected = [ - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 1, 0 ], - [ 8, 0 ], - [ 8, 0, 6, 5 ], - [ 8, 0, 6, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (no shapes)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [] - ]; - - expected = [ - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty shapes (i.e., zero-dimensional array broadcasting))', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [] ], - [ [], [] ], - [ [], [], [] ], - [ [], [ 0 ] ], - [ [ 0 ], [] ], - [ [], [ 0, 0 ] ], - [ [ 0, 0 ], [] ], - [ [], [ 1, 0 ] ], - [ [], [ 0, 1 ] ], - [ [], [ 3, 3 ] ], - [ [], [ 3, 3 ], [] ] - ]; - - expected = [ - [], - [], - [], - [ 0 ], - [ 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 3, 3 ], - [ 3, 3 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (single shape)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 7 ] ], - [ [ 1, 1 ] ], - [ [ 5, 6, 1 ] ] - ]; - - expected = [ - [ 7 ], - [ 1, 1 ], - [ 5, 6, 1 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function returns `null` if provided incompatible shapes', function test( t ) { - var actual; - var values; - var i; - - values = [ - [ [ 3 ], [ 4 ] ], - [ [ 2, 3 ], [ 2 ] ], - [ [ 3 ], [ 3 ], [ 4 ] ], - [ [ 1, 3, 4 ], [ 2, 3, 3 ] ], - [ [ 1, 2 ], [ 3, 1 ], [ 3, 2 ], [ 10, 5 ] ], - [ [ 2 ], [ 2, 3 ] ], - [ [ 2 ], [ 2 ], [ 2 ], [ 2 ], [ 3 ], [ 3 ], [ 3 ], [ 3 ] ], - [ [ 9, 0, 9 ], [ 0, 9, 0 ] ], - [ [ 9, 9, 9 ], [ 0, 9, 9 ] ], - [ [ 9, 0, 9 ], [ 9, 9, 9 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 0 ] ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.strictEqual( actual, null, 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); From a726e1bb76b2385070da060eff8532432750aee5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Dec 2022 03:23:23 +0000 Subject: [PATCH 026/158] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 5f0a571..ca2c60e 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,8 @@ }, "dependencies": { "@stdlib/types": "^0.0.x", - "@stdlib/utils-library-manifest": "^0.0.x" + "@stdlib/utils-library-manifest": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x" }, "devDependencies": { "@stdlib/bench": "^0.0.x", @@ -84,4 +85,4 @@ "type": "patreon", "url": "https://www.patreon.com/athan" } -} +} \ No newline at end of file From 903b7fb8444443fdd80a9357d6103e456b9e3158 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Dec 2022 13:30:10 +0000 Subject: [PATCH 027/158] Remove files --- browser.js | 3 - browser.js.map | 1 - index.js | 3 - index.js.map | 1 - stats_browser.html | 4044 -------------------------------------------- stats_node.html | 4044 -------------------------------------------- 6 files changed, 8096 deletions(-) delete mode 100644 browser.js delete mode 100644 browser.js.map delete mode 100644 index.js delete mode 100644 index.js.map delete mode 100644 stats_browser.html delete mode 100644 stats_node.html diff --git a/browser.js b/browser.js deleted file mode 100644 index 3c259e1..0000000 --- a/browser.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); -//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map deleted file mode 100644 index aa4b2bb..0000000 --- a/browser.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"browser.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/index.js b/index.js deleted file mode 100644 index 635432d..0000000 --- a/index.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); -//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map deleted file mode 100644 index 0c02c0f..0000000 --- a/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/stats_browser.html b/stats_browser.html deleted file mode 100644 index 7284dc8..0000000 --- a/stats_browser.html +++ /dev/null @@ -1,4044 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - diff --git a/stats_node.html b/stats_node.html deleted file mode 100644 index ecb9362..0000000 --- a/stats_node.html +++ /dev/null @@ -1,4044 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 9ea412fe1495870702de2ff5d1ee7ee1631481e1 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Dec 2022 13:31:00 +0000 Subject: [PATCH 028/158] 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 | 178 +- benchmark/benchmark.js | 112 - benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 152 - branches.md | 53 - browser.js | 3 + browser.js.map | 1 + docs/repl.txt | 39 - docs/types/index.d.ts | 177 - docs/types/test.ts | 45 - examples/c/Makefile | 146 - examples/c/example.c | 50 - examples/index.js | 54 - .../stdlib/ndarray/base/broadcast_shapes.h | 40 - index.js | 3 + index.js.map | 1 + lib/index.js | 45 - lib/main.js | 256 -- manifest.json | 38 - package.json | 58 +- src/main.c | 118 - stats_browser.html | 4044 +++++++++++++++++ stats_node.html | 4044 +++++++++++++++++ test/test.js | 230 - 47 files changed, 8134 insertions(+), 4829 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.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 branches.md create mode 100644 browser.js create mode 100644 browser.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/index.d.ts delete mode 100644 docs/types/test.ts delete mode 100644 examples/c/Makefile delete mode 100644 examples/c/example.c delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/broadcast_shapes.h create mode 100644 index.js create mode 100644 index.js.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 manifest.json delete mode 100644 src/main.c create mode 100644 stats_browser.html create mode 100644 stats_node.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 8fc3535..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-12-01T00:59:07.590Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 7f004ad..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 8a49110..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 0bff0a0..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 12 * * 5' - - # 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 +``` + +If no recognized module system is present, access bundle contents via the global scope: + +```html + ``` #### broadcastShapes( shapes ) @@ -232,9 +240,14 @@ var sh = broadcastShapes( [ sh1, sh2 ] ); -```javascript -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); +```html + + + + + + + + ```
@@ -275,131 +293,7 @@ for ( i = 0; i < shapes.length; i++ ) { -* * * - -
- -## C APIs - - - -
- -
- - - - - -
- -### Usage - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -``` - -#### stdlib_ndarray_broadcast_shapes( M, \*\*shapes, \*ndims, \*out ) - -Broadcasts array shapes to a single shape. - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -int64_t N1 = 4; -int64_t sh1[] = { 8, 1, 6, 1 }; - -int64_t N2 = 3; -int64_t sh2[] = { 7, 1, 5 }; - -int64_t ndims[] = { N1, N2 }; -int64_t *shapes[] = { sh1, sh2 }; - -int64_t out[] = { 0, 0, 0, 0 }; -int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -if ( status != 0 ) { - // Handle error... -} -``` - -The function accepts the following arguments: - -- **M**: `[in] int64_t` number of shape arrays. -- **shapes**: `[in] int64_t**` array of shape arrays (dimensions). -- **ndims**: `[in] int64_t*` number of dimensions for each respective shape array. -- **out**: `[out] int64_t*` output shape array. - -```c -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ); -``` - -If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). - -
- - - - - -
- -### Notes - -- Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. - -
- - - - - -
- -### Examples - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main() { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} -``` - -
- - - -
- diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index fa610dc..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,112 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pkg = require( './../package.json' ).name; -var broadcastShapes = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::two_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ] ], - [ [ 3, 2 ], [ 3, 1 ] ], - [ [ 1, 1 ], [ 2, 2 ] ], - [ [ 1 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::three_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::four_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ], [ 8, 1, 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ], [ 1, 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ], [ 1, 1, 2, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ], [ 1 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ], [ 5, 1, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/c/Makefile b/benchmark/c/Makefile deleted file mode 100644 index 5dc545c..0000000 --- a/benchmark/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := benchmark.out - - -# RULES # - -#/ -# Compiles C source files. -# -# @param {string} SOURCE_FILES - list of C source files -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lpthread -lblas`) -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [C_COMPILER] - C compiler -# @param {string} [CFLAGS] - C compiler flags -# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} SOURCE_FILES - list of C source files -# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {(string|void)} LIBRARIES - list of libraries (e.g., `-lpthread -lblas`) -# @param {(string|void)} LIBPATH - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} CC - C compiler -# @param {string} CFLAGS - C compiler flags -# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled benchmarks. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/benchmark/c/benchmark.c b/benchmark/c/benchmark.c deleted file mode 100644 index be62cd5..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,152 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/** -* Benchmark `broadcast_shapes`. -*/ -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "broadcast-shapes" -#define ITERATIONS 1000000 -#define REPEATS 3 - -/** -* Prints the TAP version. -*/ -void print_version() { - printf( "TAP version 13\n" ); -} - -/** -* Prints the TAP summary. -* -* @param total total number of tests -* @param passing total number of passing tests -*/ -void print_summary( int total, int passing ) { - printf( "#\n" ); - printf( "1..%d\n", total ); // TAP plan - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); -} - -/** -* Prints benchmarks results. -* -* @param elapsed elapsed time in seconds -*/ -void print_results( double elapsed ) { - double rate = (double)ITERATIONS / elapsed; - printf( " ---\n" ); - printf( " iterations: %d\n", ITERATIONS ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", rate ); - printf( " ...\n" ); -} - -/** -* Returns a clock time. -* -* @return clock time -*/ -double tic() { - struct timeval now; - gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; -} - -/** -* Generates a random double on the interval [0,1]. -* -* @return random double -*/ -double rand_double() { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark() { - double elapsed; - int8_t status; - double t; - int i; - - int64_t sh1[] = { 8, 1, 6, 1 }; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { 4, 3 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( out[ 0 ] != 8 ) { - printf( "unexpected result\n" ); - } - if ( out[ 1 ] != 7 ) { - printf( "unexpected result\n" ); - } - if ( out[ 2 ] != 6 ) { - printf( "unexpected result\n" ); - } - if ( out[ 3 ] != 5 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Main execution sequence. -*/ -int main( void ) { - double elapsed; - int i; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - for ( i = 0; i < REPEATS; i++ ) { - printf( "# c::native::%s::two_arrays\n", NAME ); - elapsed = benchmark(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", i+1 ); - } - print_summary( REPEATS, REPEATS ); -} diff --git a/branches.md b/branches.md deleted file mode 100644 index 20fbab5..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes" -click B href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/main" -click C href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production" -click D href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm \ No newline at end of file diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..3c259e1 --- /dev/null +++ b/browser.js @@ -0,0 +1,3 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map new file mode 100644 index 0000000..aa4b2bb --- /dev/null +++ b/browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"browser.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f1d92f6..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,39 +0,0 @@ - -{{alias}}( shapes ) - Broadcasts array shapes to a single shape. - - Two respective dimensions in two shape arrays are compatible if - - 1. the dimensions are equal. - 2. one dimension is `1`. - - The function returns `null` if provided incompatible shapes (i.e., shapes - which cannot be broadcast with one another). - - Parameters - ---------- - shapes: Array - Array of shape arrays. - - Returns - ------- - out: Array|null - Broadcast shape. - - Examples - -------- - // Compatible shapes: - > var sh1 = [ 8, 1, 6, 1 ]; - > var sh2 = [ 7, 1, 5 ]; - > var sh = {{alias}}( [ sh1, sh2 ] ) - [ 8, 7, 6, 5 ] - - // Incompatible shapes: - > sh1 = [ 3, 2 ]; - > sh1 = [ 2, 3 ]; - > sh = {{alias}}( [ sh1, sh2 ] ) - null - - See Also - -------- - diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts deleted file mode 100644 index f46767d..0000000 --- a/docs/types/index.d.ts +++ /dev/null @@ -1,177 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ArrayLike } from '@stdlib/types/array'; - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param shapes - array shapes -* @returns broadcast shape -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -declare function broadcastShapes( shapes: ArrayLike> ): ArrayLike; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = broadcastShapes; diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 2886539..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 broadcastShapes = require( './index' ); - - -// TESTS // - -// The function returns an array of numbers... -{ - broadcastShapes( [ [ 1, 2 ], [ 2, 2 ] ] ); // $ExpectType ArrayLike -} - -// The compiler throws an error if the function is not provided an array-like object containing array-like objects containing numbers... -{ - broadcastShapes( '5' ); // $ExpectError - broadcastShapes( 5 ); // $ExpectError - broadcastShapes( true ); // $ExpectError - broadcastShapes( false ); // $ExpectError - broadcastShapes( null ); // $ExpectError - broadcastShapes( {} ); // $ExpectError - broadcastShapes( [ '5' ] ); // $ExpectError - broadcastShapes( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - broadcastShapes(); // $ExpectError - broadcastShapes( [ [ 1, 2, 3 ] ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/c/Makefile b/examples/c/Makefile deleted file mode 100644 index 70c91f4..0000000 --- a/examples/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := example.out - - -# RULES # - -#/ -# Compiles source files. -# -# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) -# @param {string} [CFLAGS] - C compiler options -# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) -# @param {string} [SOURCE_FILES] - list of source files -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} CC - C compiler (e.g., `gcc`) -# @param {string} CFLAGS - C compiler options -# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) -# @param {string} SOURCE_FILES - list of source files -# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) -# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled examples. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/examples/c/example.c b/examples/c/example.c deleted file mode 100644 index fae2252..0000000 --- a/examples/c/example.c +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main() { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 28811f9..0000000 --- a/examples/index.js +++ /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. -*/ - -'use strict'; - -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( './../lib' ); - -var shapes; -var out; -var sh; -var i; -var j; - -function shape2string( shape ) { - return lpad( shape.join( ' x ' ), 20, ' ' ); -} - -shapes = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] -]; - -for ( i = 0; i < shapes.length; i++ ) { - sh = shapes[ i ]; - for ( j = 0; j < sh.length; j++ ) { - console.log( shape2string( sh[ j ] ) ); - } - console.log( lpad( '', 20, '-' ) ); - - out = broadcastShapes( sh ); - console.log( shape2string( out )+'\n' ); -} diff --git a/include/stdlib/ndarray/base/broadcast_shapes.h b/include/stdlib/ndarray/base/broadcast_shapes.h deleted file mode 100644 index e23dce1..0000000 --- a/include/stdlib/ndarray/base/broadcast_shapes.h +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#ifndef STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H -#define STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H - -#include - -/* -* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. -*/ -#ifdef __cplusplus -extern "C" { -#endif - -/** -* Broadcasts array shapes to a single shape. -*/ -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H diff --git a/index.js b/index.js new file mode 100644 index 0000000..635432d --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map new file mode 100644 index 0000000..0c02c0f --- /dev/null +++ b/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 0c9817e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Broadcast array shapes to a single shape. -* -* @module @stdlib/ndarray-base-broadcast-shapes -* -* @example -* var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); -* -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -*/ - -// 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 8558e60..0000000 --- a/lib/main.js +++ /dev/null @@ -1,256 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param {Array} shapes - array of shape arrays -* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`) -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [ 8, 0, 1, 6, 1 ], -* [ 8, 8, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -function broadcastShapes( shapes ) { - var ndims; - var out; - var dim; - var sh; - var n1; - var n2; - var d; - var M; - var N; - var i; - var j; - - M = shapes.length; - out = []; - if ( M === 0 ) { - return out; - } - sh = shapes[ 0 ]; - N = sh.length; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M === 1 ) { - // Need to manually copy to output shape, as shapes could be array-like objects... - for ( i = 0; i < N; i++ ) { - out.push( sh[ i ] ); - } - return out; - } - // Determine the maximum dimensionality... - ndims = [ N ]; - for ( i = 1; i < M; i++ ) { - ndims.push( shapes[ i ].length ); - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Initialize the output array... - for ( i = 0; i < N; i++ ) { - out.push( 0 ); - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim === 1 ) { - dim = d; - continue; - } - if ( d === 1 || dim === d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return null; - } - out[ i ] = dim; - i -= 1; - } - return out; -} - - -// EXPORTS // - -module.exports = broadcastShapes; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 890a937..0000000 --- a/manifest.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "options": {}, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [] - } - ] -} diff --git a/package.json b/package.json index ca2c60e..096d386 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,7 @@ "version": "0.0.8", "description": "Broadcast array shapes to a single shape.", "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", - "include": "./include", - "lib": "./lib", - "src": "./src", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "main": "./index.js", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,33 +12,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/types": "^0.0.x", - "@stdlib/utils-library-manifest": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x" - }, - "devDependencies": { - "@stdlib/bench": "^0.0.x", - "@stdlib/string-left-pad": "^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", "stdtypes", @@ -80,9 +27,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" } -} \ No newline at end of file +} diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 35a3654..0000000 --- a/src/main.c +++ /dev/null @@ -1,118 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). -* -* - Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. -* -* @param M number of array shapes -* @param shapes pointer to an array containing shape arrays -* @param ndims array containing the number of dimensions for (i.e., length of) each respective shape array -* @param out pointer to output array -* @return status -* -* @example -* #include "stdlib/ndarray/base/broadcast_shapes.h" -* #include -* -* int64_t N1 = 4; -* int64_t sh1[] = { 8, 1, 6, 1 }; -* -* int64_t N2 = 3; -* int64_t sh2[] = { 7, 1, 5 }; -* -* int64_t ndims[] = { N1, N2 }; -* int64_t *shapes[] = { sh1, sh2 }; -* -* int64_t out[] = { 0, 0, 0, 0 }; -* int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -*/ -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ) { - int64_t dim; - int64_t *sh; - int64_t n1; - int64_t n2; - int64_t d; - int64_t N; - int64_t i; - int64_t j; - - if ( M == 0 ) { - return 0; - } - sh = shapes[ 0 ]; - N = ndims[ 0 ]; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M == 1 ) { - for ( i = 0; i < N; i++ ) { - out[ i ] = sh[ i ]; - } - return 0; - } - // Determine the maximum dimensionality... - for ( i = 1; i < M; i++ ) { - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim == 1 ) { - dim = d; - continue; - } - if ( d == 1 || dim == d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return -1; - } - out[ i ] = dim; - i -= 1; - } - return 0; -} diff --git a/stats_browser.html b/stats_browser.html new file mode 100644 index 0000000..4d6ddf9 --- /dev/null +++ b/stats_browser.html @@ -0,0 +1,4044 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/stats_node.html b/stats_node.html new file mode 100644 index 0000000..778e908 --- /dev/null +++ b/stats_node.html @@ -0,0 +1,4044 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 63f703c..0000000 --- a/test/test.js +++ /dev/null @@ -1,230 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var broadcastShapes = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastShapes, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] - ]; - - expected = [ - [ 1, 2 ], - [ 3, 4 ], - [ 5, 6, 7 ], - [ 3, 3 ], - [ 3 ], - [ 3, 2 ], - [ 2, 3 ], - [ 1, 2 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty dims)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 0 ], [ 0, 0 ] ], - [ [ 0, 1 ], [ 0, 0 ] ], - [ [ 1, 0 ], [ 0, 1 ] ], - [ [ 1, 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 1, 0 ] ], - [ [ 1, 1 ], [ 0, 1 ] ], - [ [ 0 ], [ 0, 0 ] ], - [ [ 0 ], [ 0, 1 ] ], - [ [ 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 0 ] ], - [ [ 1 ], [ 0, 1 ] ], - [ [ 1 ], [ 1, 0 ] ], - [ [ 1 ], [ 8, 0 ] ], - [ [ 8, 1, 6, 1 ], [ 0, 1, 5 ] ], - [ [ 8, 0, 6, 1 ], [ 1, 5 ] ] - ]; - - expected = [ - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 1, 0 ], - [ 8, 0 ], - [ 8, 0, 6, 5 ], - [ 8, 0, 6, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (no shapes)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [] - ]; - - expected = [ - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty shapes (i.e., zero-dimensional array broadcasting))', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [] ], - [ [], [] ], - [ [], [], [] ], - [ [], [ 0 ] ], - [ [ 0 ], [] ], - [ [], [ 0, 0 ] ], - [ [ 0, 0 ], [] ], - [ [], [ 1, 0 ] ], - [ [], [ 0, 1 ] ], - [ [], [ 3, 3 ] ], - [ [], [ 3, 3 ], [] ] - ]; - - expected = [ - [], - [], - [], - [ 0 ], - [ 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 3, 3 ], - [ 3, 3 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (single shape)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 7 ] ], - [ [ 1, 1 ] ], - [ [ 5, 6, 1 ] ] - ]; - - expected = [ - [ 7 ], - [ 1, 1 ], - [ 5, 6, 1 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function returns `null` if provided incompatible shapes', function test( t ) { - var actual; - var values; - var i; - - values = [ - [ [ 3 ], [ 4 ] ], - [ [ 2, 3 ], [ 2 ] ], - [ [ 3 ], [ 3 ], [ 4 ] ], - [ [ 1, 3, 4 ], [ 2, 3, 3 ] ], - [ [ 1, 2 ], [ 3, 1 ], [ 3, 2 ], [ 10, 5 ] ], - [ [ 2 ], [ 2, 3 ] ], - [ [ 2 ], [ 2 ], [ 2 ], [ 2 ], [ 3 ], [ 3 ], [ 3 ], [ 3 ] ], - [ [ 9, 0, 9 ], [ 0, 9, 0 ] ], - [ [ 9, 9, 9 ], [ 0, 9, 9 ] ], - [ [ 9, 0, 9 ], [ 9, 9, 9 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 0 ] ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.strictEqual( actual, null, 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); From b556a22db37b3bc6972a39ca3bb6b0fe6146d44c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Jan 2023 02:01:52 +0000 Subject: [PATCH 029/158] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 5ef7a9b..794dc3f 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,8 @@ }, "dependencies": { "@stdlib/types": "^0.0.x", - "@stdlib/utils-library-manifest": "^0.0.x" + "@stdlib/utils-library-manifest": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x" }, "devDependencies": { "@stdlib/bench": "^0.0.x", @@ -84,4 +85,4 @@ "type": "patreon", "url": "https://www.patreon.com/athan" } -} +} \ No newline at end of file From a1e3af1d683217cb093cefec0eadbd4f5dc68458 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Jan 2023 11:08:12 +0000 Subject: [PATCH 030/158] Remove files --- browser.js | 3 - browser.js.map | 1 - index.js | 3 - index.js.map | 1 - stats_browser.html | 4044 -------------------------------------------- stats_node.html | 4044 -------------------------------------------- 6 files changed, 8096 deletions(-) delete mode 100644 browser.js delete mode 100644 browser.js.map delete mode 100644 index.js delete mode 100644 index.js.map delete mode 100644 stats_browser.html delete mode 100644 stats_node.html diff --git a/browser.js b/browser.js deleted file mode 100644 index 3c259e1..0000000 --- a/browser.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); -//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map deleted file mode 100644 index aa4b2bb..0000000 --- a/browser.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"browser.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/index.js b/index.js deleted file mode 100644 index 635432d..0000000 --- a/index.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); -//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map deleted file mode 100644 index 0c02c0f..0000000 --- a/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/stats_browser.html b/stats_browser.html deleted file mode 100644 index 4d6ddf9..0000000 --- a/stats_browser.html +++ /dev/null @@ -1,4044 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - diff --git a/stats_node.html b/stats_node.html deleted file mode 100644 index 778e908..0000000 --- a/stats_node.html +++ /dev/null @@ -1,4044 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From f003df4d323ca3a7669fa7dc4329bc70c138b656 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Jan 2023 11:08:53 +0000 Subject: [PATCH 031/158] 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 | 178 +- benchmark/benchmark.js | 112 - benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 152 - branches.md | 53 - browser.js | 3 + browser.js.map | 1 + docs/repl.txt | 39 - docs/types/index.d.ts | 177 - docs/types/test.ts | 45 - examples/c/Makefile | 146 - examples/c/example.c | 50 - examples/index.js | 54 - .../stdlib/ndarray/base/broadcast_shapes.h | 40 - index.js | 3 + index.js.map | 1 + lib/index.js | 45 - lib/main.js | 256 -- manifest.json | 38 - package.json | 58 +- src/main.c | 118 - stats_browser.html | 4044 +++++++++++++++++ stats_node.html | 4044 +++++++++++++++++ test/test.js | 230 - 47 files changed, 8134 insertions(+), 4840 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.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 branches.md create mode 100644 browser.js create mode 100644 browser.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/index.d.ts delete mode 100644 docs/types/test.ts delete mode 100644 examples/c/Makefile delete mode 100644 examples/c/example.c delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/broadcast_shapes.h create mode 100644 index.js create mode 100644 index.js.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 manifest.json delete mode 100644 src/main.c create mode 100644 stats_browser.html create mode 100644 stats_node.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 2d2a20b..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-01-01T00:46:11.692Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 7f004ad..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 8a49110..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 0bff0a0..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 12 * * 5' - - # 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 +``` + +If no recognized module system is present, access bundle contents via the global scope: + +```html + ``` #### broadcastShapes( shapes ) @@ -232,9 +240,14 @@ var sh = broadcastShapes( [ sh1, sh2 ] ); -```javascript -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); +```html + + + + + + + + ```
@@ -275,131 +293,7 @@ for ( i = 0; i < shapes.length; i++ ) { -* * * - -
- -## C APIs - - - -
- -
- - - - - -
- -### Usage - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -``` - -#### stdlib_ndarray_broadcast_shapes( M, \*\*shapes, \*ndims, \*out ) - -Broadcasts array shapes to a single shape. - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -int64_t N1 = 4; -int64_t sh1[] = { 8, 1, 6, 1 }; - -int64_t N2 = 3; -int64_t sh2[] = { 7, 1, 5 }; - -int64_t ndims[] = { N1, N2 }; -int64_t *shapes[] = { sh1, sh2 }; - -int64_t out[] = { 0, 0, 0, 0 }; -int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -if ( status != 0 ) { - // Handle error... -} -``` - -The function accepts the following arguments: - -- **M**: `[in] int64_t` number of shape arrays. -- **shapes**: `[in] int64_t**` array of shape arrays (dimensions). -- **ndims**: `[in] int64_t*` number of dimensions for each respective shape array. -- **out**: `[out] int64_t*` output shape array. - -```c -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ); -``` - -If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). - -
- - - - - -
- -### Notes - -- Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. - -
- - - - - -
- -### Examples - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main() { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} -``` - -
- - - -
- diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index fa610dc..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,112 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pkg = require( './../package.json' ).name; -var broadcastShapes = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::two_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ] ], - [ [ 3, 2 ], [ 3, 1 ] ], - [ [ 1, 1 ], [ 2, 2 ] ], - [ [ 1 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::three_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::four_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ], [ 8, 1, 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ], [ 1, 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ], [ 1, 1, 2, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ], [ 1 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ], [ 5, 1, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/c/Makefile b/benchmark/c/Makefile deleted file mode 100644 index 5dc545c..0000000 --- a/benchmark/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := benchmark.out - - -# RULES # - -#/ -# Compiles C source files. -# -# @param {string} SOURCE_FILES - list of C source files -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lpthread -lblas`) -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [C_COMPILER] - C compiler -# @param {string} [CFLAGS] - C compiler flags -# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} SOURCE_FILES - list of C source files -# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {(string|void)} LIBRARIES - list of libraries (e.g., `-lpthread -lblas`) -# @param {(string|void)} LIBPATH - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} CC - C compiler -# @param {string} CFLAGS - C compiler flags -# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled benchmarks. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/benchmark/c/benchmark.c b/benchmark/c/benchmark.c deleted file mode 100644 index be62cd5..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,152 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/** -* Benchmark `broadcast_shapes`. -*/ -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "broadcast-shapes" -#define ITERATIONS 1000000 -#define REPEATS 3 - -/** -* Prints the TAP version. -*/ -void print_version() { - printf( "TAP version 13\n" ); -} - -/** -* Prints the TAP summary. -* -* @param total total number of tests -* @param passing total number of passing tests -*/ -void print_summary( int total, int passing ) { - printf( "#\n" ); - printf( "1..%d\n", total ); // TAP plan - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); -} - -/** -* Prints benchmarks results. -* -* @param elapsed elapsed time in seconds -*/ -void print_results( double elapsed ) { - double rate = (double)ITERATIONS / elapsed; - printf( " ---\n" ); - printf( " iterations: %d\n", ITERATIONS ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", rate ); - printf( " ...\n" ); -} - -/** -* Returns a clock time. -* -* @return clock time -*/ -double tic() { - struct timeval now; - gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; -} - -/** -* Generates a random double on the interval [0,1]. -* -* @return random double -*/ -double rand_double() { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark() { - double elapsed; - int8_t status; - double t; - int i; - - int64_t sh1[] = { 8, 1, 6, 1 }; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { 4, 3 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( out[ 0 ] != 8 ) { - printf( "unexpected result\n" ); - } - if ( out[ 1 ] != 7 ) { - printf( "unexpected result\n" ); - } - if ( out[ 2 ] != 6 ) { - printf( "unexpected result\n" ); - } - if ( out[ 3 ] != 5 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Main execution sequence. -*/ -int main( void ) { - double elapsed; - int i; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - for ( i = 0; i < REPEATS; i++ ) { - printf( "# c::native::%s::two_arrays\n", NAME ); - elapsed = benchmark(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", i+1 ); - } - print_summary( REPEATS, REPEATS ); -} diff --git a/branches.md b/branches.md deleted file mode 100644 index 20fbab5..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes" -click B href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/main" -click C href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production" -click D href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm \ No newline at end of file diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..3faa0cd --- /dev/null +++ b/browser.js @@ -0,0 +1,3 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map new file mode 100644 index 0000000..aa4b2bb --- /dev/null +++ b/browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"browser.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f1d92f6..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,39 +0,0 @@ - -{{alias}}( shapes ) - Broadcasts array shapes to a single shape. - - Two respective dimensions in two shape arrays are compatible if - - 1. the dimensions are equal. - 2. one dimension is `1`. - - The function returns `null` if provided incompatible shapes (i.e., shapes - which cannot be broadcast with one another). - - Parameters - ---------- - shapes: Array - Array of shape arrays. - - Returns - ------- - out: Array|null - Broadcast shape. - - Examples - -------- - // Compatible shapes: - > var sh1 = [ 8, 1, 6, 1 ]; - > var sh2 = [ 7, 1, 5 ]; - > var sh = {{alias}}( [ sh1, sh2 ] ) - [ 8, 7, 6, 5 ] - - // Incompatible shapes: - > sh1 = [ 3, 2 ]; - > sh1 = [ 2, 3 ]; - > sh = {{alias}}( [ sh1, sh2 ] ) - null - - See Also - -------- - diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts deleted file mode 100644 index f46767d..0000000 --- a/docs/types/index.d.ts +++ /dev/null @@ -1,177 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ArrayLike } from '@stdlib/types/array'; - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param shapes - array shapes -* @returns broadcast shape -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -declare function broadcastShapes( shapes: ArrayLike> ): ArrayLike; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = broadcastShapes; diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 2886539..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 broadcastShapes = require( './index' ); - - -// TESTS // - -// The function returns an array of numbers... -{ - broadcastShapes( [ [ 1, 2 ], [ 2, 2 ] ] ); // $ExpectType ArrayLike -} - -// The compiler throws an error if the function is not provided an array-like object containing array-like objects containing numbers... -{ - broadcastShapes( '5' ); // $ExpectError - broadcastShapes( 5 ); // $ExpectError - broadcastShapes( true ); // $ExpectError - broadcastShapes( false ); // $ExpectError - broadcastShapes( null ); // $ExpectError - broadcastShapes( {} ); // $ExpectError - broadcastShapes( [ '5' ] ); // $ExpectError - broadcastShapes( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - broadcastShapes(); // $ExpectError - broadcastShapes( [ [ 1, 2, 3 ] ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/c/Makefile b/examples/c/Makefile deleted file mode 100644 index 70c91f4..0000000 --- a/examples/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := example.out - - -# RULES # - -#/ -# Compiles source files. -# -# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) -# @param {string} [CFLAGS] - C compiler options -# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) -# @param {string} [SOURCE_FILES] - list of source files -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} CC - C compiler (e.g., `gcc`) -# @param {string} CFLAGS - C compiler options -# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) -# @param {string} SOURCE_FILES - list of source files -# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) -# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled examples. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/examples/c/example.c b/examples/c/example.c deleted file mode 100644 index fae2252..0000000 --- a/examples/c/example.c +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main() { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 28811f9..0000000 --- a/examples/index.js +++ /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. -*/ - -'use strict'; - -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( './../lib' ); - -var shapes; -var out; -var sh; -var i; -var j; - -function shape2string( shape ) { - return lpad( shape.join( ' x ' ), 20, ' ' ); -} - -shapes = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] -]; - -for ( i = 0; i < shapes.length; i++ ) { - sh = shapes[ i ]; - for ( j = 0; j < sh.length; j++ ) { - console.log( shape2string( sh[ j ] ) ); - } - console.log( lpad( '', 20, '-' ) ); - - out = broadcastShapes( sh ); - console.log( shape2string( out )+'\n' ); -} diff --git a/include/stdlib/ndarray/base/broadcast_shapes.h b/include/stdlib/ndarray/base/broadcast_shapes.h deleted file mode 100644 index e23dce1..0000000 --- a/include/stdlib/ndarray/base/broadcast_shapes.h +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#ifndef STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H -#define STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H - -#include - -/* -* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. -*/ -#ifdef __cplusplus -extern "C" { -#endif - -/** -* Broadcasts array shapes to a single shape. -*/ -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H diff --git a/index.js b/index.js new file mode 100644 index 0000000..c1ce4fa --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map new file mode 100644 index 0000000..0c02c0f --- /dev/null +++ b/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 0c9817e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Broadcast array shapes to a single shape. -* -* @module @stdlib/ndarray-base-broadcast-shapes -* -* @example -* var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); -* -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -*/ - -// 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 8558e60..0000000 --- a/lib/main.js +++ /dev/null @@ -1,256 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param {Array} shapes - array of shape arrays -* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`) -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [ 8, 0, 1, 6, 1 ], -* [ 8, 8, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -function broadcastShapes( shapes ) { - var ndims; - var out; - var dim; - var sh; - var n1; - var n2; - var d; - var M; - var N; - var i; - var j; - - M = shapes.length; - out = []; - if ( M === 0 ) { - return out; - } - sh = shapes[ 0 ]; - N = sh.length; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M === 1 ) { - // Need to manually copy to output shape, as shapes could be array-like objects... - for ( i = 0; i < N; i++ ) { - out.push( sh[ i ] ); - } - return out; - } - // Determine the maximum dimensionality... - ndims = [ N ]; - for ( i = 1; i < M; i++ ) { - ndims.push( shapes[ i ].length ); - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Initialize the output array... - for ( i = 0; i < N; i++ ) { - out.push( 0 ); - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim === 1 ) { - dim = d; - continue; - } - if ( d === 1 || dim === d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return null; - } - out[ i ] = dim; - i -= 1; - } - return out; -} - - -// EXPORTS // - -module.exports = broadcastShapes; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 890a937..0000000 --- a/manifest.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "options": {}, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [] - } - ] -} diff --git a/package.json b/package.json index 794dc3f..096d386 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,7 @@ "version": "0.0.8", "description": "Broadcast array shapes to a single shape.", "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", - "include": "./include", - "lib": "./lib", - "src": "./src", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "main": "./index.js", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,33 +12,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/types": "^0.0.x", - "@stdlib/utils-library-manifest": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x" - }, - "devDependencies": { - "@stdlib/bench": "^0.0.x", - "@stdlib/string-left-pad": "^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", "stdtypes", @@ -80,9 +27,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" } -} \ No newline at end of file +} diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 35a3654..0000000 --- a/src/main.c +++ /dev/null @@ -1,118 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). -* -* - Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. -* -* @param M number of array shapes -* @param shapes pointer to an array containing shape arrays -* @param ndims array containing the number of dimensions for (i.e., length of) each respective shape array -* @param out pointer to output array -* @return status -* -* @example -* #include "stdlib/ndarray/base/broadcast_shapes.h" -* #include -* -* int64_t N1 = 4; -* int64_t sh1[] = { 8, 1, 6, 1 }; -* -* int64_t N2 = 3; -* int64_t sh2[] = { 7, 1, 5 }; -* -* int64_t ndims[] = { N1, N2 }; -* int64_t *shapes[] = { sh1, sh2 }; -* -* int64_t out[] = { 0, 0, 0, 0 }; -* int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -*/ -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ) { - int64_t dim; - int64_t *sh; - int64_t n1; - int64_t n2; - int64_t d; - int64_t N; - int64_t i; - int64_t j; - - if ( M == 0 ) { - return 0; - } - sh = shapes[ 0 ]; - N = ndims[ 0 ]; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M == 1 ) { - for ( i = 0; i < N; i++ ) { - out[ i ] = sh[ i ]; - } - return 0; - } - // Determine the maximum dimensionality... - for ( i = 1; i < M; i++ ) { - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim == 1 ) { - dim = d; - continue; - } - if ( d == 1 || dim == d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return -1; - } - out[ i ] = dim; - i -= 1; - } - return 0; -} diff --git a/stats_browser.html b/stats_browser.html new file mode 100644 index 0000000..fdc3f7b --- /dev/null +++ b/stats_browser.html @@ -0,0 +1,4044 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/stats_node.html b/stats_node.html new file mode 100644 index 0000000..9663b6f --- /dev/null +++ b/stats_node.html @@ -0,0 +1,4044 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 63f703c..0000000 --- a/test/test.js +++ /dev/null @@ -1,230 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var broadcastShapes = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastShapes, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] - ]; - - expected = [ - [ 1, 2 ], - [ 3, 4 ], - [ 5, 6, 7 ], - [ 3, 3 ], - [ 3 ], - [ 3, 2 ], - [ 2, 3 ], - [ 1, 2 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty dims)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 0 ], [ 0, 0 ] ], - [ [ 0, 1 ], [ 0, 0 ] ], - [ [ 1, 0 ], [ 0, 1 ] ], - [ [ 1, 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 1, 0 ] ], - [ [ 1, 1 ], [ 0, 1 ] ], - [ [ 0 ], [ 0, 0 ] ], - [ [ 0 ], [ 0, 1 ] ], - [ [ 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 0 ] ], - [ [ 1 ], [ 0, 1 ] ], - [ [ 1 ], [ 1, 0 ] ], - [ [ 1 ], [ 8, 0 ] ], - [ [ 8, 1, 6, 1 ], [ 0, 1, 5 ] ], - [ [ 8, 0, 6, 1 ], [ 1, 5 ] ] - ]; - - expected = [ - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 1, 0 ], - [ 8, 0 ], - [ 8, 0, 6, 5 ], - [ 8, 0, 6, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (no shapes)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [] - ]; - - expected = [ - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty shapes (i.e., zero-dimensional array broadcasting))', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [] ], - [ [], [] ], - [ [], [], [] ], - [ [], [ 0 ] ], - [ [ 0 ], [] ], - [ [], [ 0, 0 ] ], - [ [ 0, 0 ], [] ], - [ [], [ 1, 0 ] ], - [ [], [ 0, 1 ] ], - [ [], [ 3, 3 ] ], - [ [], [ 3, 3 ], [] ] - ]; - - expected = [ - [], - [], - [], - [ 0 ], - [ 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 3, 3 ], - [ 3, 3 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (single shape)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 7 ] ], - [ [ 1, 1 ] ], - [ [ 5, 6, 1 ] ] - ]; - - expected = [ - [ 7 ], - [ 1, 1 ], - [ 5, 6, 1 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function returns `null` if provided incompatible shapes', function test( t ) { - var actual; - var values; - var i; - - values = [ - [ [ 3 ], [ 4 ] ], - [ [ 2, 3 ], [ 2 ] ], - [ [ 3 ], [ 3 ], [ 4 ] ], - [ [ 1, 3, 4 ], [ 2, 3, 3 ] ], - [ [ 1, 2 ], [ 3, 1 ], [ 3, 2 ], [ 10, 5 ] ], - [ [ 2 ], [ 2, 3 ] ], - [ [ 2 ], [ 2 ], [ 2 ], [ 2 ], [ 3 ], [ 3 ], [ 3 ], [ 3 ] ], - [ [ 9, 0, 9 ], [ 0, 9, 0 ] ], - [ [ 9, 9, 9 ], [ 0, 9, 9 ] ], - [ [ 9, 0, 9 ], [ 9, 9, 9 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 0 ] ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.strictEqual( actual, null, 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); From 76d30ed14e04ba7c1d3c799d17c10380dc1a46b0 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Feb 2023 03:28:40 +0000 Subject: [PATCH 032/158] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 5ef7a9b..794dc3f 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,8 @@ }, "dependencies": { "@stdlib/types": "^0.0.x", - "@stdlib/utils-library-manifest": "^0.0.x" + "@stdlib/utils-library-manifest": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x" }, "devDependencies": { "@stdlib/bench": "^0.0.x", @@ -84,4 +85,4 @@ "type": "patreon", "url": "https://www.patreon.com/athan" } -} +} \ No newline at end of file From f55da1a081f42369e805d794d6c76a2bffa34943 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Feb 2023 08:26:55 +0000 Subject: [PATCH 033/158] Remove files --- browser.js | 3 - browser.js.map | 1 - index.js | 3 - index.js.map | 1 - stats_browser.html | 4044 -------------------------------------------- stats_node.html | 4044 -------------------------------------------- 6 files changed, 8096 deletions(-) delete mode 100644 browser.js delete mode 100644 browser.js.map delete mode 100644 index.js delete mode 100644 index.js.map delete mode 100644 stats_browser.html delete mode 100644 stats_node.html diff --git a/browser.js b/browser.js deleted file mode 100644 index 3faa0cd..0000000 --- a/browser.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); -//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map deleted file mode 100644 index aa4b2bb..0000000 --- a/browser.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"browser.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/index.js b/index.js deleted file mode 100644 index c1ce4fa..0000000 --- a/index.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); -//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map deleted file mode 100644 index 0c02c0f..0000000 --- a/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/stats_browser.html b/stats_browser.html deleted file mode 100644 index fdc3f7b..0000000 --- a/stats_browser.html +++ /dev/null @@ -1,4044 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - diff --git a/stats_node.html b/stats_node.html deleted file mode 100644 index 9663b6f..0000000 --- a/stats_node.html +++ /dev/null @@ -1,4044 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 2e9588216fdecd70c907e5b186ad393e59499758 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Feb 2023 08:27:34 +0000 Subject: [PATCH 034/158] 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 | 178 +- benchmark/benchmark.js | 112 - benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 152 - branches.md | 53 - browser.js | 3 + browser.js.map | 1 + docs/repl.txt | 39 - docs/types/index.d.ts | 177 - docs/types/test.ts | 45 - examples/c/Makefile | 146 - examples/c/example.c | 50 - examples/index.js | 54 - .../stdlib/ndarray/base/broadcast_shapes.h | 40 - index.js | 3 + index.js.map | 1 + lib/index.js | 45 - lib/main.js | 256 - manifest.json | 38 - package.json | 58 +- src/main.c | 118 - stats_browser.html | 6177 +++++++++++++++++ stats_node.html | 6177 +++++++++++++++++ test/test.js | 230 - 47 files changed, 12400 insertions(+), 4840 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.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 branches.md create mode 100644 browser.js create mode 100644 browser.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/index.d.ts delete mode 100644 docs/types/test.ts delete mode 100644 examples/c/Makefile delete mode 100644 examples/c/example.c delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/broadcast_shapes.h create mode 100644 index.js create mode 100644 index.js.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 manifest.json delete mode 100644 src/main.c create mode 100644 stats_browser.html create mode 100644 stats_node.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 196e5e8..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-02-01T00:55:36.593Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 7f004ad..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 8a49110..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 0bff0a0..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 12 * * 5' - - # 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 +``` + +If no recognized module system is present, access bundle contents via the global scope: + +```html + ``` #### broadcastShapes( shapes ) @@ -232,9 +240,14 @@ var sh = broadcastShapes( [ sh1, sh2 ] ); -```javascript -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); +```html + + + + + + + + ```
@@ -275,131 +293,7 @@ for ( i = 0; i < shapes.length; i++ ) { -* * * - -
- -## C APIs - - - -
- -
- - - - - -
- -### Usage - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -``` - -#### stdlib_ndarray_broadcast_shapes( M, \*\*shapes, \*ndims, \*out ) - -Broadcasts array shapes to a single shape. - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -int64_t N1 = 4; -int64_t sh1[] = { 8, 1, 6, 1 }; - -int64_t N2 = 3; -int64_t sh2[] = { 7, 1, 5 }; - -int64_t ndims[] = { N1, N2 }; -int64_t *shapes[] = { sh1, sh2 }; - -int64_t out[] = { 0, 0, 0, 0 }; -int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -if ( status != 0 ) { - // Handle error... -} -``` - -The function accepts the following arguments: - -- **M**: `[in] int64_t` number of shape arrays. -- **shapes**: `[in] int64_t**` array of shape arrays (dimensions). -- **ndims**: `[in] int64_t*` number of dimensions for each respective shape array. -- **out**: `[out] int64_t*` output shape array. - -```c -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ); -``` - -If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). - -
- - - - - -
- -### Notes - -- Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. - -
- - - - - -
- -### Examples - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main() { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} -``` - -
- - - -
- diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index fa610dc..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,112 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pkg = require( './../package.json' ).name; -var broadcastShapes = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::two_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ] ], - [ [ 3, 2 ], [ 3, 1 ] ], - [ [ 1, 1 ], [ 2, 2 ] ], - [ [ 1 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::three_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::four_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ], [ 8, 1, 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ], [ 1, 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ], [ 1, 1, 2, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ], [ 1 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ], [ 5, 1, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/c/Makefile b/benchmark/c/Makefile deleted file mode 100644 index 5dc545c..0000000 --- a/benchmark/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := benchmark.out - - -# RULES # - -#/ -# Compiles C source files. -# -# @param {string} SOURCE_FILES - list of C source files -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lpthread -lblas`) -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [C_COMPILER] - C compiler -# @param {string} [CFLAGS] - C compiler flags -# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} SOURCE_FILES - list of C source files -# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {(string|void)} LIBRARIES - list of libraries (e.g., `-lpthread -lblas`) -# @param {(string|void)} LIBPATH - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} CC - C compiler -# @param {string} CFLAGS - C compiler flags -# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled benchmarks. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/benchmark/c/benchmark.c b/benchmark/c/benchmark.c deleted file mode 100644 index be62cd5..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,152 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/** -* Benchmark `broadcast_shapes`. -*/ -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "broadcast-shapes" -#define ITERATIONS 1000000 -#define REPEATS 3 - -/** -* Prints the TAP version. -*/ -void print_version() { - printf( "TAP version 13\n" ); -} - -/** -* Prints the TAP summary. -* -* @param total total number of tests -* @param passing total number of passing tests -*/ -void print_summary( int total, int passing ) { - printf( "#\n" ); - printf( "1..%d\n", total ); // TAP plan - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); -} - -/** -* Prints benchmarks results. -* -* @param elapsed elapsed time in seconds -*/ -void print_results( double elapsed ) { - double rate = (double)ITERATIONS / elapsed; - printf( " ---\n" ); - printf( " iterations: %d\n", ITERATIONS ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", rate ); - printf( " ...\n" ); -} - -/** -* Returns a clock time. -* -* @return clock time -*/ -double tic() { - struct timeval now; - gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; -} - -/** -* Generates a random double on the interval [0,1]. -* -* @return random double -*/ -double rand_double() { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark() { - double elapsed; - int8_t status; - double t; - int i; - - int64_t sh1[] = { 8, 1, 6, 1 }; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { 4, 3 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( out[ 0 ] != 8 ) { - printf( "unexpected result\n" ); - } - if ( out[ 1 ] != 7 ) { - printf( "unexpected result\n" ); - } - if ( out[ 2 ] != 6 ) { - printf( "unexpected result\n" ); - } - if ( out[ 3 ] != 5 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Main execution sequence. -*/ -int main( void ) { - double elapsed; - int i; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - for ( i = 0; i < REPEATS; i++ ) { - printf( "# c::native::%s::two_arrays\n", NAME ); - elapsed = benchmark(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", i+1 ); - } - print_summary( REPEATS, REPEATS ); -} diff --git a/branches.md b/branches.md deleted file mode 100644 index 20fbab5..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes" -click B href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/main" -click C href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production" -click D href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm \ No newline at end of file diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..3faa0cd --- /dev/null +++ b/browser.js @@ -0,0 +1,3 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map new file mode 100644 index 0000000..aa4b2bb --- /dev/null +++ b/browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"browser.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f1d92f6..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,39 +0,0 @@ - -{{alias}}( shapes ) - Broadcasts array shapes to a single shape. - - Two respective dimensions in two shape arrays are compatible if - - 1. the dimensions are equal. - 2. one dimension is `1`. - - The function returns `null` if provided incompatible shapes (i.e., shapes - which cannot be broadcast with one another). - - Parameters - ---------- - shapes: Array - Array of shape arrays. - - Returns - ------- - out: Array|null - Broadcast shape. - - Examples - -------- - // Compatible shapes: - > var sh1 = [ 8, 1, 6, 1 ]; - > var sh2 = [ 7, 1, 5 ]; - > var sh = {{alias}}( [ sh1, sh2 ] ) - [ 8, 7, 6, 5 ] - - // Incompatible shapes: - > sh1 = [ 3, 2 ]; - > sh1 = [ 2, 3 ]; - > sh = {{alias}}( [ sh1, sh2 ] ) - null - - See Also - -------- - diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts deleted file mode 100644 index f46767d..0000000 --- a/docs/types/index.d.ts +++ /dev/null @@ -1,177 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ArrayLike } from '@stdlib/types/array'; - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param shapes - array shapes -* @returns broadcast shape -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -declare function broadcastShapes( shapes: ArrayLike> ): ArrayLike; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = broadcastShapes; diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 2886539..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 broadcastShapes = require( './index' ); - - -// TESTS // - -// The function returns an array of numbers... -{ - broadcastShapes( [ [ 1, 2 ], [ 2, 2 ] ] ); // $ExpectType ArrayLike -} - -// The compiler throws an error if the function is not provided an array-like object containing array-like objects containing numbers... -{ - broadcastShapes( '5' ); // $ExpectError - broadcastShapes( 5 ); // $ExpectError - broadcastShapes( true ); // $ExpectError - broadcastShapes( false ); // $ExpectError - broadcastShapes( null ); // $ExpectError - broadcastShapes( {} ); // $ExpectError - broadcastShapes( [ '5' ] ); // $ExpectError - broadcastShapes( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - broadcastShapes(); // $ExpectError - broadcastShapes( [ [ 1, 2, 3 ] ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/c/Makefile b/examples/c/Makefile deleted file mode 100644 index 70c91f4..0000000 --- a/examples/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := example.out - - -# RULES # - -#/ -# Compiles source files. -# -# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) -# @param {string} [CFLAGS] - C compiler options -# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) -# @param {string} [SOURCE_FILES] - list of source files -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} CC - C compiler (e.g., `gcc`) -# @param {string} CFLAGS - C compiler options -# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) -# @param {string} SOURCE_FILES - list of source files -# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) -# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled examples. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/examples/c/example.c b/examples/c/example.c deleted file mode 100644 index fae2252..0000000 --- a/examples/c/example.c +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main() { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 28811f9..0000000 --- a/examples/index.js +++ /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. -*/ - -'use strict'; - -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( './../lib' ); - -var shapes; -var out; -var sh; -var i; -var j; - -function shape2string( shape ) { - return lpad( shape.join( ' x ' ), 20, ' ' ); -} - -shapes = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] -]; - -for ( i = 0; i < shapes.length; i++ ) { - sh = shapes[ i ]; - for ( j = 0; j < sh.length; j++ ) { - console.log( shape2string( sh[ j ] ) ); - } - console.log( lpad( '', 20, '-' ) ); - - out = broadcastShapes( sh ); - console.log( shape2string( out )+'\n' ); -} diff --git a/include/stdlib/ndarray/base/broadcast_shapes.h b/include/stdlib/ndarray/base/broadcast_shapes.h deleted file mode 100644 index e23dce1..0000000 --- a/include/stdlib/ndarray/base/broadcast_shapes.h +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#ifndef STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H -#define STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H - -#include - -/* -* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. -*/ -#ifdef __cplusplus -extern "C" { -#endif - -/** -* Broadcasts array shapes to a single shape. -*/ -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H diff --git a/index.js b/index.js new file mode 100644 index 0000000..c1ce4fa --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map new file mode 100644 index 0000000..0c02c0f --- /dev/null +++ b/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 0c9817e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Broadcast array shapes to a single shape. -* -* @module @stdlib/ndarray-base-broadcast-shapes -* -* @example -* var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); -* -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -*/ - -// 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 8558e60..0000000 --- a/lib/main.js +++ /dev/null @@ -1,256 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param {Array} shapes - array of shape arrays -* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`) -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [ 8, 0, 1, 6, 1 ], -* [ 8, 8, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -function broadcastShapes( shapes ) { - var ndims; - var out; - var dim; - var sh; - var n1; - var n2; - var d; - var M; - var N; - var i; - var j; - - M = shapes.length; - out = []; - if ( M === 0 ) { - return out; - } - sh = shapes[ 0 ]; - N = sh.length; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M === 1 ) { - // Need to manually copy to output shape, as shapes could be array-like objects... - for ( i = 0; i < N; i++ ) { - out.push( sh[ i ] ); - } - return out; - } - // Determine the maximum dimensionality... - ndims = [ N ]; - for ( i = 1; i < M; i++ ) { - ndims.push( shapes[ i ].length ); - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Initialize the output array... - for ( i = 0; i < N; i++ ) { - out.push( 0 ); - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim === 1 ) { - dim = d; - continue; - } - if ( d === 1 || dim === d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return null; - } - out[ i ] = dim; - i -= 1; - } - return out; -} - - -// EXPORTS // - -module.exports = broadcastShapes; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 890a937..0000000 --- a/manifest.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "options": {}, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [] - } - ] -} diff --git a/package.json b/package.json index 794dc3f..096d386 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,7 @@ "version": "0.0.8", "description": "Broadcast array shapes to a single shape.", "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", - "include": "./include", - "lib": "./lib", - "src": "./src", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "main": "./index.js", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,33 +12,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/types": "^0.0.x", - "@stdlib/utils-library-manifest": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x" - }, - "devDependencies": { - "@stdlib/bench": "^0.0.x", - "@stdlib/string-left-pad": "^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", "stdtypes", @@ -80,9 +27,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" } -} \ No newline at end of file +} diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 35a3654..0000000 --- a/src/main.c +++ /dev/null @@ -1,118 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). -* -* - Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. -* -* @param M number of array shapes -* @param shapes pointer to an array containing shape arrays -* @param ndims array containing the number of dimensions for (i.e., length of) each respective shape array -* @param out pointer to output array -* @return status -* -* @example -* #include "stdlib/ndarray/base/broadcast_shapes.h" -* #include -* -* int64_t N1 = 4; -* int64_t sh1[] = { 8, 1, 6, 1 }; -* -* int64_t N2 = 3; -* int64_t sh2[] = { 7, 1, 5 }; -* -* int64_t ndims[] = { N1, N2 }; -* int64_t *shapes[] = { sh1, sh2 }; -* -* int64_t out[] = { 0, 0, 0, 0 }; -* int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -*/ -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ) { - int64_t dim; - int64_t *sh; - int64_t n1; - int64_t n2; - int64_t d; - int64_t N; - int64_t i; - int64_t j; - - if ( M == 0 ) { - return 0; - } - sh = shapes[ 0 ]; - N = ndims[ 0 ]; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M == 1 ) { - for ( i = 0; i < N; i++ ) { - out[ i ] = sh[ i ]; - } - return 0; - } - // Determine the maximum dimensionality... - for ( i = 1; i < M; i++ ) { - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim == 1 ) { - dim = d; - continue; - } - if ( d == 1 || dim == d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return -1; - } - out[ i ] = dim; - i -= 1; - } - return 0; -} diff --git a/stats_browser.html b/stats_browser.html new file mode 100644 index 0000000..9e57329 --- /dev/null +++ b/stats_browser.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/stats_node.html b/stats_node.html new file mode 100644 index 0000000..dd7d25d --- /dev/null +++ b/stats_node.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 63f703c..0000000 --- a/test/test.js +++ /dev/null @@ -1,230 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var broadcastShapes = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastShapes, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] - ]; - - expected = [ - [ 1, 2 ], - [ 3, 4 ], - [ 5, 6, 7 ], - [ 3, 3 ], - [ 3 ], - [ 3, 2 ], - [ 2, 3 ], - [ 1, 2 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty dims)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 0 ], [ 0, 0 ] ], - [ [ 0, 1 ], [ 0, 0 ] ], - [ [ 1, 0 ], [ 0, 1 ] ], - [ [ 1, 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 1, 0 ] ], - [ [ 1, 1 ], [ 0, 1 ] ], - [ [ 0 ], [ 0, 0 ] ], - [ [ 0 ], [ 0, 1 ] ], - [ [ 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 0 ] ], - [ [ 1 ], [ 0, 1 ] ], - [ [ 1 ], [ 1, 0 ] ], - [ [ 1 ], [ 8, 0 ] ], - [ [ 8, 1, 6, 1 ], [ 0, 1, 5 ] ], - [ [ 8, 0, 6, 1 ], [ 1, 5 ] ] - ]; - - expected = [ - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 1, 0 ], - [ 8, 0 ], - [ 8, 0, 6, 5 ], - [ 8, 0, 6, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (no shapes)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [] - ]; - - expected = [ - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty shapes (i.e., zero-dimensional array broadcasting))', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [] ], - [ [], [] ], - [ [], [], [] ], - [ [], [ 0 ] ], - [ [ 0 ], [] ], - [ [], [ 0, 0 ] ], - [ [ 0, 0 ], [] ], - [ [], [ 1, 0 ] ], - [ [], [ 0, 1 ] ], - [ [], [ 3, 3 ] ], - [ [], [ 3, 3 ], [] ] - ]; - - expected = [ - [], - [], - [], - [ 0 ], - [ 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 3, 3 ], - [ 3, 3 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (single shape)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 7 ] ], - [ [ 1, 1 ] ], - [ [ 5, 6, 1 ] ] - ]; - - expected = [ - [ 7 ], - [ 1, 1 ], - [ 5, 6, 1 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function returns `null` if provided incompatible shapes', function test( t ) { - var actual; - var values; - var i; - - values = [ - [ [ 3 ], [ 4 ] ], - [ [ 2, 3 ], [ 2 ] ], - [ [ 3 ], [ 3 ], [ 4 ] ], - [ [ 1, 3, 4 ], [ 2, 3, 3 ] ], - [ [ 1, 2 ], [ 3, 1 ], [ 3, 2 ], [ 10, 5 ] ], - [ [ 2 ], [ 2, 3 ] ], - [ [ 2 ], [ 2 ], [ 2 ], [ 2 ], [ 3 ], [ 3 ], [ 3 ], [ 3 ] ], - [ [ 9, 0, 9 ], [ 0, 9, 0 ] ], - [ [ 9, 9, 9 ], [ 0, 9, 9 ] ], - [ [ 9, 0, 9 ], [ 9, 9, 9 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 0 ] ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.strictEqual( actual, null, 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); From de0f3301ce1b6bbc2de857891a2cb078fc611d85 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Mar 2023 02:22:58 +0000 Subject: [PATCH 035/158] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 7abde4e..a26ab7b 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,8 @@ }, "dependencies": { "@stdlib/types": "^0.0.14", - "@stdlib/utils-library-manifest": "^0.0.8" + "@stdlib/utils-library-manifest": "^0.0.8", + "@stdlib/error-tools-fmtprodmsg": "^0.0.2" }, "devDependencies": { "@stdlib/bench": "^0.0.12", @@ -84,4 +85,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From 15fe1d0a80c4ba5412e413593fd6991e323cf976 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Mar 2023 05:45:51 +0000 Subject: [PATCH 036/158] Remove files --- browser.js | 3 - browser.js.map | 1 - index.js | 3 - index.js.map | 1 - stats_browser.html | 6177 -------------------------------------------- stats_node.html | 6177 -------------------------------------------- 6 files changed, 12362 deletions(-) delete mode 100644 browser.js delete mode 100644 browser.js.map delete mode 100644 index.js delete mode 100644 index.js.map delete mode 100644 stats_browser.html delete mode 100644 stats_node.html diff --git a/browser.js b/browser.js deleted file mode 100644 index 3faa0cd..0000000 --- a/browser.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); -//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map deleted file mode 100644 index aa4b2bb..0000000 --- a/browser.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"browser.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/index.js b/index.js deleted file mode 100644 index c1ce4fa..0000000 --- a/index.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); -//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map deleted file mode 100644 index 0c02c0f..0000000 --- a/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/stats_browser.html b/stats_browser.html deleted file mode 100644 index 9e57329..0000000 --- a/stats_browser.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - diff --git a/stats_node.html b/stats_node.html deleted file mode 100644 index dd7d25d..0000000 --- a/stats_node.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From fc85c0fda01f684e7efefbd1ecd2654b0ba3104e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Mar 2023 05:46:28 +0000 Subject: [PATCH 037/158] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 798 --- .github/workflows/publish.yml | 236 - .github/workflows/test.yml | 97 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 178 +- benchmark/benchmark.js | 112 - benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 152 - branches.md | 53 - browser.js | 3 + browser.js.map | 1 + docs/repl.txt | 39 - docs/types/index.d.ts | 177 - docs/types/test.ts | 45 - examples/c/Makefile | 146 - examples/c/example.c | 50 - examples/index.js | 54 - .../stdlib/ndarray/base/broadcast_shapes.h | 40 - index.js | 3 + index.js.map | 1 + lib/index.js | 45 - lib/main.js | 256 - manifest.json | 38 - package.json | 58 +- src/main.c | 118 - stats_browser.html | 6177 +++++++++++++++++ stats_node.html | 6177 +++++++++++++++++ test/test.js | 230 - 47 files changed, 12400 insertions(+), 4975 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.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 branches.md create mode 100644 browser.js create mode 100644 browser.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/index.d.ts delete mode 100644 docs/types/test.ts delete mode 100644 examples/c/Makefile delete mode 100644 examples/c/example.c delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/broadcast_shapes.h create mode 100644 index.js create mode 100644 index.js.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 manifest.json delete mode 100644 src/main.c create mode 100644 stats_browser.html create mode 100644 stats_node.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 9ab94cb..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-03-01T01:34:56.003Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 7f004ad..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 8a49110..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 0bff0a0..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 12 * * 5' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 3e8e2db..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,798 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n +``` + +If no recognized module system is present, access bundle contents via the global scope: + +```html + ``` #### broadcastShapes( shapes ) @@ -232,9 +240,14 @@ var sh = broadcastShapes( [ sh1, sh2 ] ); -```javascript -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); +```html + + + + + + + + ```
@@ -275,131 +293,7 @@ for ( i = 0; i < shapes.length; i++ ) { -* * * - -
- -## C APIs - - - -
- -
- - - - - -
- -### Usage - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -``` - -#### stdlib_ndarray_broadcast_shapes( M, \*\*shapes, \*ndims, \*out ) - -Broadcasts array shapes to a single shape. - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -int64_t N1 = 4; -int64_t sh1[] = { 8, 1, 6, 1 }; - -int64_t N2 = 3; -int64_t sh2[] = { 7, 1, 5 }; - -int64_t ndims[] = { N1, N2 }; -int64_t *shapes[] = { sh1, sh2 }; - -int64_t out[] = { 0, 0, 0, 0 }; -int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -if ( status != 0 ) { - // Handle error... -} -``` - -The function accepts the following arguments: - -- **M**: `[in] int64_t` number of shape arrays. -- **shapes**: `[in] int64_t**` array of shape arrays (dimensions). -- **ndims**: `[in] int64_t*` number of dimensions for each respective shape array. -- **out**: `[out] int64_t*` output shape array. - -```c -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ); -``` - -If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). - -
- - - - - -
- -### Notes - -- Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. - -
- - - - - -
- -### Examples - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main() { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} -``` - -
- - - -
- diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index fa610dc..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,112 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pkg = require( './../package.json' ).name; -var broadcastShapes = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::two_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ] ], - [ [ 3, 2 ], [ 3, 1 ] ], - [ [ 1, 1 ], [ 2, 2 ] ], - [ [ 1 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::three_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::four_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ], [ 8, 1, 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ], [ 1, 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ], [ 1, 1, 2, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ], [ 1 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ], [ 5, 1, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/c/Makefile b/benchmark/c/Makefile deleted file mode 100644 index 5dc545c..0000000 --- a/benchmark/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := benchmark.out - - -# RULES # - -#/ -# Compiles C source files. -# -# @param {string} SOURCE_FILES - list of C source files -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lpthread -lblas`) -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [C_COMPILER] - C compiler -# @param {string} [CFLAGS] - C compiler flags -# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} SOURCE_FILES - list of C source files -# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {(string|void)} LIBRARIES - list of libraries (e.g., `-lpthread -lblas`) -# @param {(string|void)} LIBPATH - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} CC - C compiler -# @param {string} CFLAGS - C compiler flags -# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled benchmarks. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/benchmark/c/benchmark.c b/benchmark/c/benchmark.c deleted file mode 100644 index be62cd5..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,152 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/** -* Benchmark `broadcast_shapes`. -*/ -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "broadcast-shapes" -#define ITERATIONS 1000000 -#define REPEATS 3 - -/** -* Prints the TAP version. -*/ -void print_version() { - printf( "TAP version 13\n" ); -} - -/** -* Prints the TAP summary. -* -* @param total total number of tests -* @param passing total number of passing tests -*/ -void print_summary( int total, int passing ) { - printf( "#\n" ); - printf( "1..%d\n", total ); // TAP plan - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); -} - -/** -* Prints benchmarks results. -* -* @param elapsed elapsed time in seconds -*/ -void print_results( double elapsed ) { - double rate = (double)ITERATIONS / elapsed; - printf( " ---\n" ); - printf( " iterations: %d\n", ITERATIONS ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", rate ); - printf( " ...\n" ); -} - -/** -* Returns a clock time. -* -* @return clock time -*/ -double tic() { - struct timeval now; - gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; -} - -/** -* Generates a random double on the interval [0,1]. -* -* @return random double -*/ -double rand_double() { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark() { - double elapsed; - int8_t status; - double t; - int i; - - int64_t sh1[] = { 8, 1, 6, 1 }; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { 4, 3 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( out[ 0 ] != 8 ) { - printf( "unexpected result\n" ); - } - if ( out[ 1 ] != 7 ) { - printf( "unexpected result\n" ); - } - if ( out[ 2 ] != 6 ) { - printf( "unexpected result\n" ); - } - if ( out[ 3 ] != 5 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Main execution sequence. -*/ -int main( void ) { - double elapsed; - int i; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - for ( i = 0; i < REPEATS; i++ ) { - printf( "# c::native::%s::two_arrays\n", NAME ); - elapsed = benchmark(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", i+1 ); - } - print_summary( REPEATS, REPEATS ); -} diff --git a/branches.md b/branches.md deleted file mode 100644 index 27a33c4..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes" -%% click B href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm \ No newline at end of file diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..3faa0cd --- /dev/null +++ b/browser.js @@ -0,0 +1,3 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map new file mode 100644 index 0000000..aa4b2bb --- /dev/null +++ b/browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"browser.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f1d92f6..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,39 +0,0 @@ - -{{alias}}( shapes ) - Broadcasts array shapes to a single shape. - - Two respective dimensions in two shape arrays are compatible if - - 1. the dimensions are equal. - 2. one dimension is `1`. - - The function returns `null` if provided incompatible shapes (i.e., shapes - which cannot be broadcast with one another). - - Parameters - ---------- - shapes: Array - Array of shape arrays. - - Returns - ------- - out: Array|null - Broadcast shape. - - Examples - -------- - // Compatible shapes: - > var sh1 = [ 8, 1, 6, 1 ]; - > var sh2 = [ 7, 1, 5 ]; - > var sh = {{alias}}( [ sh1, sh2 ] ) - [ 8, 7, 6, 5 ] - - // Incompatible shapes: - > sh1 = [ 3, 2 ]; - > sh1 = [ 2, 3 ]; - > sh = {{alias}}( [ sh1, sh2 ] ) - null - - See Also - -------- - diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts deleted file mode 100644 index f46767d..0000000 --- a/docs/types/index.d.ts +++ /dev/null @@ -1,177 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ArrayLike } from '@stdlib/types/array'; - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param shapes - array shapes -* @returns broadcast shape -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -declare function broadcastShapes( shapes: ArrayLike> ): ArrayLike; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = broadcastShapes; diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 2886539..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 broadcastShapes = require( './index' ); - - -// TESTS // - -// The function returns an array of numbers... -{ - broadcastShapes( [ [ 1, 2 ], [ 2, 2 ] ] ); // $ExpectType ArrayLike -} - -// The compiler throws an error if the function is not provided an array-like object containing array-like objects containing numbers... -{ - broadcastShapes( '5' ); // $ExpectError - broadcastShapes( 5 ); // $ExpectError - broadcastShapes( true ); // $ExpectError - broadcastShapes( false ); // $ExpectError - broadcastShapes( null ); // $ExpectError - broadcastShapes( {} ); // $ExpectError - broadcastShapes( [ '5' ] ); // $ExpectError - broadcastShapes( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - broadcastShapes(); // $ExpectError - broadcastShapes( [ [ 1, 2, 3 ] ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/c/Makefile b/examples/c/Makefile deleted file mode 100644 index 70c91f4..0000000 --- a/examples/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := example.out - - -# RULES # - -#/ -# Compiles source files. -# -# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) -# @param {string} [CFLAGS] - C compiler options -# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) -# @param {string} [SOURCE_FILES] - list of source files -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} CC - C compiler (e.g., `gcc`) -# @param {string} CFLAGS - C compiler options -# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) -# @param {string} SOURCE_FILES - list of source files -# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) -# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled examples. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/examples/c/example.c b/examples/c/example.c deleted file mode 100644 index fae2252..0000000 --- a/examples/c/example.c +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main() { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 28811f9..0000000 --- a/examples/index.js +++ /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. -*/ - -'use strict'; - -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( './../lib' ); - -var shapes; -var out; -var sh; -var i; -var j; - -function shape2string( shape ) { - return lpad( shape.join( ' x ' ), 20, ' ' ); -} - -shapes = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] -]; - -for ( i = 0; i < shapes.length; i++ ) { - sh = shapes[ i ]; - for ( j = 0; j < sh.length; j++ ) { - console.log( shape2string( sh[ j ] ) ); - } - console.log( lpad( '', 20, '-' ) ); - - out = broadcastShapes( sh ); - console.log( shape2string( out )+'\n' ); -} diff --git a/include/stdlib/ndarray/base/broadcast_shapes.h b/include/stdlib/ndarray/base/broadcast_shapes.h deleted file mode 100644 index e23dce1..0000000 --- a/include/stdlib/ndarray/base/broadcast_shapes.h +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#ifndef STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H -#define STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H - -#include - -/* -* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. -*/ -#ifdef __cplusplus -extern "C" { -#endif - -/** -* Broadcasts array shapes to a single shape. -*/ -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H diff --git a/index.js b/index.js new file mode 100644 index 0000000..c1ce4fa --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map new file mode 100644 index 0000000..0c02c0f --- /dev/null +++ b/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 0c9817e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Broadcast array shapes to a single shape. -* -* @module @stdlib/ndarray-base-broadcast-shapes -* -* @example -* var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); -* -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -*/ - -// 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 8558e60..0000000 --- a/lib/main.js +++ /dev/null @@ -1,256 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param {Array} shapes - array of shape arrays -* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`) -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [ 8, 0, 1, 6, 1 ], -* [ 8, 8, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -function broadcastShapes( shapes ) { - var ndims; - var out; - var dim; - var sh; - var n1; - var n2; - var d; - var M; - var N; - var i; - var j; - - M = shapes.length; - out = []; - if ( M === 0 ) { - return out; - } - sh = shapes[ 0 ]; - N = sh.length; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M === 1 ) { - // Need to manually copy to output shape, as shapes could be array-like objects... - for ( i = 0; i < N; i++ ) { - out.push( sh[ i ] ); - } - return out; - } - // Determine the maximum dimensionality... - ndims = [ N ]; - for ( i = 1; i < M; i++ ) { - ndims.push( shapes[ i ].length ); - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Initialize the output array... - for ( i = 0; i < N; i++ ) { - out.push( 0 ); - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim === 1 ) { - dim = d; - continue; - } - if ( d === 1 || dim === d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return null; - } - out[ i ] = dim; - i -= 1; - } - return out; -} - - -// EXPORTS // - -module.exports = broadcastShapes; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 890a937..0000000 --- a/manifest.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "options": {}, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [] - } - ] -} diff --git a/package.json b/package.json index a26ab7b..4b05a44 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,7 @@ "version": "0.0.8", "description": "Broadcast array shapes to a single shape.", "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", - "include": "./include", - "lib": "./lib", - "src": "./src", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "main": "./index.js", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,33 +12,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/types": "^0.0.14", - "@stdlib/utils-library-manifest": "^0.0.8", - "@stdlib/error-tools-fmtprodmsg": "^0.0.2" - }, - "devDependencies": { - "@stdlib/bench": "^0.0.12", - "@stdlib/string-left-pad": "^0.0.9", - "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", "stdtypes", @@ -80,9 +27,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 35a3654..0000000 --- a/src/main.c +++ /dev/null @@ -1,118 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). -* -* - Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. -* -* @param M number of array shapes -* @param shapes pointer to an array containing shape arrays -* @param ndims array containing the number of dimensions for (i.e., length of) each respective shape array -* @param out pointer to output array -* @return status -* -* @example -* #include "stdlib/ndarray/base/broadcast_shapes.h" -* #include -* -* int64_t N1 = 4; -* int64_t sh1[] = { 8, 1, 6, 1 }; -* -* int64_t N2 = 3; -* int64_t sh2[] = { 7, 1, 5 }; -* -* int64_t ndims[] = { N1, N2 }; -* int64_t *shapes[] = { sh1, sh2 }; -* -* int64_t out[] = { 0, 0, 0, 0 }; -* int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -*/ -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ) { - int64_t dim; - int64_t *sh; - int64_t n1; - int64_t n2; - int64_t d; - int64_t N; - int64_t i; - int64_t j; - - if ( M == 0 ) { - return 0; - } - sh = shapes[ 0 ]; - N = ndims[ 0 ]; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M == 1 ) { - for ( i = 0; i < N; i++ ) { - out[ i ] = sh[ i ]; - } - return 0; - } - // Determine the maximum dimensionality... - for ( i = 1; i < M; i++ ) { - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim == 1 ) { - dim = d; - continue; - } - if ( d == 1 || dim == d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return -1; - } - out[ i ] = dim; - i -= 1; - } - return 0; -} diff --git a/stats_browser.html b/stats_browser.html new file mode 100644 index 0000000..5b5e5b3 --- /dev/null +++ b/stats_browser.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/stats_node.html b/stats_node.html new file mode 100644 index 0000000..fd6f7bf --- /dev/null +++ b/stats_node.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 63f703c..0000000 --- a/test/test.js +++ /dev/null @@ -1,230 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var broadcastShapes = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastShapes, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] - ]; - - expected = [ - [ 1, 2 ], - [ 3, 4 ], - [ 5, 6, 7 ], - [ 3, 3 ], - [ 3 ], - [ 3, 2 ], - [ 2, 3 ], - [ 1, 2 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty dims)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 0 ], [ 0, 0 ] ], - [ [ 0, 1 ], [ 0, 0 ] ], - [ [ 1, 0 ], [ 0, 1 ] ], - [ [ 1, 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 1, 0 ] ], - [ [ 1, 1 ], [ 0, 1 ] ], - [ [ 0 ], [ 0, 0 ] ], - [ [ 0 ], [ 0, 1 ] ], - [ [ 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 0 ] ], - [ [ 1 ], [ 0, 1 ] ], - [ [ 1 ], [ 1, 0 ] ], - [ [ 1 ], [ 8, 0 ] ], - [ [ 8, 1, 6, 1 ], [ 0, 1, 5 ] ], - [ [ 8, 0, 6, 1 ], [ 1, 5 ] ] - ]; - - expected = [ - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 1, 0 ], - [ 8, 0 ], - [ 8, 0, 6, 5 ], - [ 8, 0, 6, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (no shapes)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [] - ]; - - expected = [ - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty shapes (i.e., zero-dimensional array broadcasting))', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [] ], - [ [], [] ], - [ [], [], [] ], - [ [], [ 0 ] ], - [ [ 0 ], [] ], - [ [], [ 0, 0 ] ], - [ [ 0, 0 ], [] ], - [ [], [ 1, 0 ] ], - [ [], [ 0, 1 ] ], - [ [], [ 3, 3 ] ], - [ [], [ 3, 3 ], [] ] - ]; - - expected = [ - [], - [], - [], - [ 0 ], - [ 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 3, 3 ], - [ 3, 3 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (single shape)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 7 ] ], - [ [ 1, 1 ] ], - [ [ 5, 6, 1 ] ] - ]; - - expected = [ - [ 7 ], - [ 1, 1 ], - [ 5, 6, 1 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function returns `null` if provided incompatible shapes', function test( t ) { - var actual; - var values; - var i; - - values = [ - [ [ 3 ], [ 4 ] ], - [ [ 2, 3 ], [ 2 ] ], - [ [ 3 ], [ 3 ], [ 4 ] ], - [ [ 1, 3, 4 ], [ 2, 3, 3 ] ], - [ [ 1, 2 ], [ 3, 1 ], [ 3, 2 ], [ 10, 5 ] ], - [ [ 2 ], [ 2, 3 ] ], - [ [ 2 ], [ 2 ], [ 2 ], [ 2 ], [ 3 ], [ 3 ], [ 3 ], [ 3 ] ], - [ [ 9, 0, 9 ], [ 0, 9, 0 ] ], - [ [ 9, 9, 9 ], [ 0, 9, 9 ] ], - [ [ 9, 0, 9 ], [ 9, 9, 9 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 0 ] ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.strictEqual( actual, null, 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); From 211d742618de31bbf2bfdf0ede79f73b96de52c3 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Apr 2023 02:25:15 +0000 Subject: [PATCH 038/158] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 7abde4e..a26ab7b 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,8 @@ }, "dependencies": { "@stdlib/types": "^0.0.14", - "@stdlib/utils-library-manifest": "^0.0.8" + "@stdlib/utils-library-manifest": "^0.0.8", + "@stdlib/error-tools-fmtprodmsg": "^0.0.2" }, "devDependencies": { "@stdlib/bench": "^0.0.12", @@ -84,4 +85,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From 26f66bb86df179a273d4aac1c2d4b7edfb62d1d7 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Apr 2023 05:33:15 +0000 Subject: [PATCH 039/158] Remove files --- browser.js | 3 - browser.js.map | 1 - index.js | 3 - index.js.map | 1 - stats_browser.html | 6177 -------------------------------------------- stats_node.html | 6177 -------------------------------------------- 6 files changed, 12362 deletions(-) delete mode 100644 browser.js delete mode 100644 browser.js.map delete mode 100644 index.js delete mode 100644 index.js.map delete mode 100644 stats_browser.html delete mode 100644 stats_node.html diff --git a/browser.js b/browser.js deleted file mode 100644 index 3faa0cd..0000000 --- a/browser.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); -//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map deleted file mode 100644 index aa4b2bb..0000000 --- a/browser.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"browser.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/index.js b/index.js deleted file mode 100644 index c1ce4fa..0000000 --- a/index.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); -//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map deleted file mode 100644 index 0c02c0f..0000000 --- a/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/stats_browser.html b/stats_browser.html deleted file mode 100644 index 5b5e5b3..0000000 --- a/stats_browser.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - diff --git a/stats_node.html b/stats_node.html deleted file mode 100644 index fd6f7bf..0000000 --- a/stats_node.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 2ad3f188655d977bd211c120f3438ba14a11ac61 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Apr 2023 05:33:58 +0000 Subject: [PATCH 040/158] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 798 --- .github/workflows/publish.yml | 242 - .github/workflows/test.yml | 97 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 178 +- benchmark/benchmark.js | 112 - benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 152 - branches.md | 53 - browser.js | 3 + browser.js.map | 1 + docs/repl.txt | 39 - docs/types/index.d.ts | 177 - docs/types/test.ts | 45 - examples/c/Makefile | 146 - examples/c/example.c | 50 - examples/index.js | 54 - .../stdlib/ndarray/base/broadcast_shapes.h | 40 - index.js | 3 + index.js.map | 1 + lib/index.js | 45 - lib/main.js | 256 - manifest.json | 38 - package.json | 58 +- src/main.c | 118 - stats_browser.html | 6177 +++++++++++++++++ stats_node.html | 6177 +++++++++++++++++ test/test.js | 230 - 47 files changed, 12400 insertions(+), 4981 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.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 branches.md create mode 100644 browser.js create mode 100644 browser.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/index.d.ts delete mode 100644 docs/types/test.ts delete mode 100644 examples/c/Makefile delete mode 100644 examples/c/example.c delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/broadcast_shapes.h create mode 100644 index.js create mode 100644 index.js.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 manifest.json delete mode 100644 src/main.c create mode 100644 stats_browser.html create mode 100644 stats_node.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 cf43f4d..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-04-01T01:41:20.029Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 7f004ad..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 8a49110..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 0bff0a0..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 12 * * 5' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 3e8e2db..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,798 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n +``` + +If no recognized module system is present, access bundle contents via the global scope: + +```html + ``` #### broadcastShapes( shapes ) @@ -232,9 +240,14 @@ var sh = broadcastShapes( [ sh1, sh2 ] ); -```javascript -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); +```html + + + + + + + + ```
@@ -275,131 +293,7 @@ for ( i = 0; i < shapes.length; i++ ) { -* * * - -
- -## C APIs - - - -
- -
- - - - - -
- -### Usage - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -``` - -#### stdlib_ndarray_broadcast_shapes( M, \*\*shapes, \*ndims, \*out ) - -Broadcasts array shapes to a single shape. - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -int64_t N1 = 4; -int64_t sh1[] = { 8, 1, 6, 1 }; - -int64_t N2 = 3; -int64_t sh2[] = { 7, 1, 5 }; - -int64_t ndims[] = { N1, N2 }; -int64_t *shapes[] = { sh1, sh2 }; - -int64_t out[] = { 0, 0, 0, 0 }; -int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -if ( status != 0 ) { - // Handle error... -} -``` - -The function accepts the following arguments: - -- **M**: `[in] int64_t` number of shape arrays. -- **shapes**: `[in] int64_t**` array of shape arrays (dimensions). -- **ndims**: `[in] int64_t*` number of dimensions for each respective shape array. -- **out**: `[out] int64_t*` output shape array. - -```c -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ); -``` - -If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). - -
- - - - - -
- -### Notes - -- Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. - -
- - - - - -
- -### Examples - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main() { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} -``` - -
- - - -
- diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index fa610dc..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,112 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pkg = require( './../package.json' ).name; -var broadcastShapes = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::two_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ] ], - [ [ 3, 2 ], [ 3, 1 ] ], - [ [ 1, 1 ], [ 2, 2 ] ], - [ [ 1 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::three_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::four_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ], [ 8, 1, 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ], [ 1, 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ], [ 1, 1, 2, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ], [ 1 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ], [ 5, 1, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/c/Makefile b/benchmark/c/Makefile deleted file mode 100644 index 5dc545c..0000000 --- a/benchmark/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := benchmark.out - - -# RULES # - -#/ -# Compiles C source files. -# -# @param {string} SOURCE_FILES - list of C source files -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lpthread -lblas`) -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [C_COMPILER] - C compiler -# @param {string} [CFLAGS] - C compiler flags -# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} SOURCE_FILES - list of C source files -# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {(string|void)} LIBRARIES - list of libraries (e.g., `-lpthread -lblas`) -# @param {(string|void)} LIBPATH - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} CC - C compiler -# @param {string} CFLAGS - C compiler flags -# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled benchmarks. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/benchmark/c/benchmark.c b/benchmark/c/benchmark.c deleted file mode 100644 index be62cd5..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,152 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/** -* Benchmark `broadcast_shapes`. -*/ -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "broadcast-shapes" -#define ITERATIONS 1000000 -#define REPEATS 3 - -/** -* Prints the TAP version. -*/ -void print_version() { - printf( "TAP version 13\n" ); -} - -/** -* Prints the TAP summary. -* -* @param total total number of tests -* @param passing total number of passing tests -*/ -void print_summary( int total, int passing ) { - printf( "#\n" ); - printf( "1..%d\n", total ); // TAP plan - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); -} - -/** -* Prints benchmarks results. -* -* @param elapsed elapsed time in seconds -*/ -void print_results( double elapsed ) { - double rate = (double)ITERATIONS / elapsed; - printf( " ---\n" ); - printf( " iterations: %d\n", ITERATIONS ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", rate ); - printf( " ...\n" ); -} - -/** -* Returns a clock time. -* -* @return clock time -*/ -double tic() { - struct timeval now; - gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; -} - -/** -* Generates a random double on the interval [0,1]. -* -* @return random double -*/ -double rand_double() { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark() { - double elapsed; - int8_t status; - double t; - int i; - - int64_t sh1[] = { 8, 1, 6, 1 }; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { 4, 3 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( out[ 0 ] != 8 ) { - printf( "unexpected result\n" ); - } - if ( out[ 1 ] != 7 ) { - printf( "unexpected result\n" ); - } - if ( out[ 2 ] != 6 ) { - printf( "unexpected result\n" ); - } - if ( out[ 3 ] != 5 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Main execution sequence. -*/ -int main( void ) { - double elapsed; - int i; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - for ( i = 0; i < REPEATS; i++ ) { - printf( "# c::native::%s::two_arrays\n", NAME ); - elapsed = benchmark(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", i+1 ); - } - print_summary( REPEATS, REPEATS ); -} diff --git a/branches.md b/branches.md deleted file mode 100644 index 27a33c4..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes" -%% click B href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm \ No newline at end of file diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..3faa0cd --- /dev/null +++ b/browser.js @@ -0,0 +1,3 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map new file mode 100644 index 0000000..aa4b2bb --- /dev/null +++ b/browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"browser.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f1d92f6..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,39 +0,0 @@ - -{{alias}}( shapes ) - Broadcasts array shapes to a single shape. - - Two respective dimensions in two shape arrays are compatible if - - 1. the dimensions are equal. - 2. one dimension is `1`. - - The function returns `null` if provided incompatible shapes (i.e., shapes - which cannot be broadcast with one another). - - Parameters - ---------- - shapes: Array - Array of shape arrays. - - Returns - ------- - out: Array|null - Broadcast shape. - - Examples - -------- - // Compatible shapes: - > var sh1 = [ 8, 1, 6, 1 ]; - > var sh2 = [ 7, 1, 5 ]; - > var sh = {{alias}}( [ sh1, sh2 ] ) - [ 8, 7, 6, 5 ] - - // Incompatible shapes: - > sh1 = [ 3, 2 ]; - > sh1 = [ 2, 3 ]; - > sh = {{alias}}( [ sh1, sh2 ] ) - null - - See Also - -------- - diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts deleted file mode 100644 index f46767d..0000000 --- a/docs/types/index.d.ts +++ /dev/null @@ -1,177 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ArrayLike } from '@stdlib/types/array'; - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param shapes - array shapes -* @returns broadcast shape -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -declare function broadcastShapes( shapes: ArrayLike> ): ArrayLike; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = broadcastShapes; diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 2886539..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 broadcastShapes = require( './index' ); - - -// TESTS // - -// The function returns an array of numbers... -{ - broadcastShapes( [ [ 1, 2 ], [ 2, 2 ] ] ); // $ExpectType ArrayLike -} - -// The compiler throws an error if the function is not provided an array-like object containing array-like objects containing numbers... -{ - broadcastShapes( '5' ); // $ExpectError - broadcastShapes( 5 ); // $ExpectError - broadcastShapes( true ); // $ExpectError - broadcastShapes( false ); // $ExpectError - broadcastShapes( null ); // $ExpectError - broadcastShapes( {} ); // $ExpectError - broadcastShapes( [ '5' ] ); // $ExpectError - broadcastShapes( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - broadcastShapes(); // $ExpectError - broadcastShapes( [ [ 1, 2, 3 ] ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/c/Makefile b/examples/c/Makefile deleted file mode 100644 index 70c91f4..0000000 --- a/examples/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := example.out - - -# RULES # - -#/ -# Compiles source files. -# -# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) -# @param {string} [CFLAGS] - C compiler options -# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) -# @param {string} [SOURCE_FILES] - list of source files -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} CC - C compiler (e.g., `gcc`) -# @param {string} CFLAGS - C compiler options -# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) -# @param {string} SOURCE_FILES - list of source files -# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) -# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled examples. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/examples/c/example.c b/examples/c/example.c deleted file mode 100644 index fae2252..0000000 --- a/examples/c/example.c +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main() { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 28811f9..0000000 --- a/examples/index.js +++ /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. -*/ - -'use strict'; - -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( './../lib' ); - -var shapes; -var out; -var sh; -var i; -var j; - -function shape2string( shape ) { - return lpad( shape.join( ' x ' ), 20, ' ' ); -} - -shapes = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] -]; - -for ( i = 0; i < shapes.length; i++ ) { - sh = shapes[ i ]; - for ( j = 0; j < sh.length; j++ ) { - console.log( shape2string( sh[ j ] ) ); - } - console.log( lpad( '', 20, '-' ) ); - - out = broadcastShapes( sh ); - console.log( shape2string( out )+'\n' ); -} diff --git a/include/stdlib/ndarray/base/broadcast_shapes.h b/include/stdlib/ndarray/base/broadcast_shapes.h deleted file mode 100644 index e23dce1..0000000 --- a/include/stdlib/ndarray/base/broadcast_shapes.h +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#ifndef STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H -#define STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H - -#include - -/* -* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. -*/ -#ifdef __cplusplus -extern "C" { -#endif - -/** -* Broadcasts array shapes to a single shape. -*/ -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H diff --git a/index.js b/index.js new file mode 100644 index 0000000..c1ce4fa --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map new file mode 100644 index 0000000..0c02c0f --- /dev/null +++ b/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 0c9817e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Broadcast array shapes to a single shape. -* -* @module @stdlib/ndarray-base-broadcast-shapes -* -* @example -* var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); -* -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -*/ - -// 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 8558e60..0000000 --- a/lib/main.js +++ /dev/null @@ -1,256 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param {Array} shapes - array of shape arrays -* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`) -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [ 8, 0, 1, 6, 1 ], -* [ 8, 8, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -function broadcastShapes( shapes ) { - var ndims; - var out; - var dim; - var sh; - var n1; - var n2; - var d; - var M; - var N; - var i; - var j; - - M = shapes.length; - out = []; - if ( M === 0 ) { - return out; - } - sh = shapes[ 0 ]; - N = sh.length; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M === 1 ) { - // Need to manually copy to output shape, as shapes could be array-like objects... - for ( i = 0; i < N; i++ ) { - out.push( sh[ i ] ); - } - return out; - } - // Determine the maximum dimensionality... - ndims = [ N ]; - for ( i = 1; i < M; i++ ) { - ndims.push( shapes[ i ].length ); - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Initialize the output array... - for ( i = 0; i < N; i++ ) { - out.push( 0 ); - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim === 1 ) { - dim = d; - continue; - } - if ( d === 1 || dim === d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return null; - } - out[ i ] = dim; - i -= 1; - } - return out; -} - - -// EXPORTS // - -module.exports = broadcastShapes; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 890a937..0000000 --- a/manifest.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "options": {}, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [] - } - ] -} diff --git a/package.json b/package.json index a26ab7b..4b05a44 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,7 @@ "version": "0.0.8", "description": "Broadcast array shapes to a single shape.", "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", - "include": "./include", - "lib": "./lib", - "src": "./src", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "main": "./index.js", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,33 +12,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/types": "^0.0.14", - "@stdlib/utils-library-manifest": "^0.0.8", - "@stdlib/error-tools-fmtprodmsg": "^0.0.2" - }, - "devDependencies": { - "@stdlib/bench": "^0.0.12", - "@stdlib/string-left-pad": "^0.0.9", - "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", "stdtypes", @@ -80,9 +27,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 35a3654..0000000 --- a/src/main.c +++ /dev/null @@ -1,118 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). -* -* - Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. -* -* @param M number of array shapes -* @param shapes pointer to an array containing shape arrays -* @param ndims array containing the number of dimensions for (i.e., length of) each respective shape array -* @param out pointer to output array -* @return status -* -* @example -* #include "stdlib/ndarray/base/broadcast_shapes.h" -* #include -* -* int64_t N1 = 4; -* int64_t sh1[] = { 8, 1, 6, 1 }; -* -* int64_t N2 = 3; -* int64_t sh2[] = { 7, 1, 5 }; -* -* int64_t ndims[] = { N1, N2 }; -* int64_t *shapes[] = { sh1, sh2 }; -* -* int64_t out[] = { 0, 0, 0, 0 }; -* int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -*/ -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ) { - int64_t dim; - int64_t *sh; - int64_t n1; - int64_t n2; - int64_t d; - int64_t N; - int64_t i; - int64_t j; - - if ( M == 0 ) { - return 0; - } - sh = shapes[ 0 ]; - N = ndims[ 0 ]; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M == 1 ) { - for ( i = 0; i < N; i++ ) { - out[ i ] = sh[ i ]; - } - return 0; - } - // Determine the maximum dimensionality... - for ( i = 1; i < M; i++ ) { - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim == 1 ) { - dim = d; - continue; - } - if ( d == 1 || dim == d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return -1; - } - out[ i ] = dim; - i -= 1; - } - return 0; -} diff --git a/stats_browser.html b/stats_browser.html new file mode 100644 index 0000000..75fdc8b --- /dev/null +++ b/stats_browser.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/stats_node.html b/stats_node.html new file mode 100644 index 0000000..d0bea36 --- /dev/null +++ b/stats_node.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 63f703c..0000000 --- a/test/test.js +++ /dev/null @@ -1,230 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var broadcastShapes = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastShapes, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] - ]; - - expected = [ - [ 1, 2 ], - [ 3, 4 ], - [ 5, 6, 7 ], - [ 3, 3 ], - [ 3 ], - [ 3, 2 ], - [ 2, 3 ], - [ 1, 2 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty dims)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 0 ], [ 0, 0 ] ], - [ [ 0, 1 ], [ 0, 0 ] ], - [ [ 1, 0 ], [ 0, 1 ] ], - [ [ 1, 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 1, 0 ] ], - [ [ 1, 1 ], [ 0, 1 ] ], - [ [ 0 ], [ 0, 0 ] ], - [ [ 0 ], [ 0, 1 ] ], - [ [ 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 0 ] ], - [ [ 1 ], [ 0, 1 ] ], - [ [ 1 ], [ 1, 0 ] ], - [ [ 1 ], [ 8, 0 ] ], - [ [ 8, 1, 6, 1 ], [ 0, 1, 5 ] ], - [ [ 8, 0, 6, 1 ], [ 1, 5 ] ] - ]; - - expected = [ - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 1, 0 ], - [ 8, 0 ], - [ 8, 0, 6, 5 ], - [ 8, 0, 6, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (no shapes)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [] - ]; - - expected = [ - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty shapes (i.e., zero-dimensional array broadcasting))', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [] ], - [ [], [] ], - [ [], [], [] ], - [ [], [ 0 ] ], - [ [ 0 ], [] ], - [ [], [ 0, 0 ] ], - [ [ 0, 0 ], [] ], - [ [], [ 1, 0 ] ], - [ [], [ 0, 1 ] ], - [ [], [ 3, 3 ] ], - [ [], [ 3, 3 ], [] ] - ]; - - expected = [ - [], - [], - [], - [ 0 ], - [ 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 3, 3 ], - [ 3, 3 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (single shape)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 7 ] ], - [ [ 1, 1 ] ], - [ [ 5, 6, 1 ] ] - ]; - - expected = [ - [ 7 ], - [ 1, 1 ], - [ 5, 6, 1 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function returns `null` if provided incompatible shapes', function test( t ) { - var actual; - var values; - var i; - - values = [ - [ [ 3 ], [ 4 ] ], - [ [ 2, 3 ], [ 2 ] ], - [ [ 3 ], [ 3 ], [ 4 ] ], - [ [ 1, 3, 4 ], [ 2, 3, 3 ] ], - [ [ 1, 2 ], [ 3, 1 ], [ 3, 2 ], [ 10, 5 ] ], - [ [ 2 ], [ 2, 3 ] ], - [ [ 2 ], [ 2 ], [ 2 ], [ 2 ], [ 3 ], [ 3 ], [ 3 ], [ 3 ] ], - [ [ 9, 0, 9 ], [ 0, 9, 0 ] ], - [ [ 9, 9, 9 ], [ 0, 9, 9 ] ], - [ [ 9, 0, 9 ], [ 9, 9, 9 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 0 ] ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.strictEqual( actual, null, 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); From ab3a896e332bf519f83b9a6a347584fc39478ce3 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 May 2023 02:20:12 +0000 Subject: [PATCH 041/158] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 7abde4e..a26ab7b 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,8 @@ }, "dependencies": { "@stdlib/types": "^0.0.14", - "@stdlib/utils-library-manifest": "^0.0.8" + "@stdlib/utils-library-manifest": "^0.0.8", + "@stdlib/error-tools-fmtprodmsg": "^0.0.2" }, "devDependencies": { "@stdlib/bench": "^0.0.12", @@ -84,4 +85,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From 606dab9700b9420c354a672e21e6815699da3c6b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 May 2023 05:22:18 +0000 Subject: [PATCH 042/158] Remove files --- browser.js | 3 - browser.js.map | 1 - index.js | 3 - index.js.map | 1 - stats_browser.html | 6177 -------------------------------------------- stats_node.html | 6177 -------------------------------------------- 6 files changed, 12362 deletions(-) delete mode 100644 browser.js delete mode 100644 browser.js.map delete mode 100644 index.js delete mode 100644 index.js.map delete mode 100644 stats_browser.html delete mode 100644 stats_node.html diff --git a/browser.js b/browser.js deleted file mode 100644 index 3faa0cd..0000000 --- a/browser.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); -//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map deleted file mode 100644 index aa4b2bb..0000000 --- a/browser.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"browser.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/index.js b/index.js deleted file mode 100644 index c1ce4fa..0000000 --- a/index.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); -//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map deleted file mode 100644 index 0c02c0f..0000000 --- a/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/stats_browser.html b/stats_browser.html deleted file mode 100644 index 75fdc8b..0000000 --- a/stats_browser.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - diff --git a/stats_node.html b/stats_node.html deleted file mode 100644 index d0bea36..0000000 --- a/stats_node.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 77ae8a805c92e67f57c4134c52f3df5f1f3ac78f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 May 2023 05:22:59 +0000 Subject: [PATCH 043/158] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 798 --- .github/workflows/publish.yml | 242 - .github/workflows/test.yml | 97 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 178 +- benchmark/benchmark.js | 112 - benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 152 - branches.md | 53 - browser.js | 3 + browser.js.map | 1 + docs/repl.txt | 39 - docs/types/index.d.ts | 177 - docs/types/test.ts | 45 - examples/c/Makefile | 146 - examples/c/example.c | 50 - examples/index.js | 54 - .../stdlib/ndarray/base/broadcast_shapes.h | 40 - index.js | 3 + index.js.map | 1 + lib/index.js | 45 - lib/main.js | 256 - manifest.json | 38 - package.json | 58 +- src/main.c | 118 - stats_browser.html | 6177 +++++++++++++++++ stats_node.html | 6177 +++++++++++++++++ test/test.js | 230 - 47 files changed, 12400 insertions(+), 4981 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.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 branches.md create mode 100644 browser.js create mode 100644 browser.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/index.d.ts delete mode 100644 docs/types/test.ts delete mode 100644 examples/c/Makefile delete mode 100644 examples/c/example.c delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/broadcast_shapes.h create mode 100644 index.js create mode 100644 index.js.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 manifest.json delete mode 100644 src/main.c create mode 100644 stats_browser.html create mode 100644 stats_node.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 9e74eff..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-05-01T01:37:53.050Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 7f004ad..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 8a49110..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 0bff0a0..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 12 * * 5' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 3e8e2db..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,798 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n +``` + +If no recognized module system is present, access bundle contents via the global scope: + +```html + ``` #### broadcastShapes( shapes ) @@ -232,9 +240,14 @@ var sh = broadcastShapes( [ sh1, sh2 ] ); -```javascript -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); +```html + + + + + + + + ```
@@ -275,131 +293,7 @@ for ( i = 0; i < shapes.length; i++ ) { -* * * - -
- -## C APIs - - - -
- -
- - - - - -
- -### Usage - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -``` - -#### stdlib_ndarray_broadcast_shapes( M, \*\*shapes, \*ndims, \*out ) - -Broadcasts array shapes to a single shape. - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -int64_t N1 = 4; -int64_t sh1[] = { 8, 1, 6, 1 }; - -int64_t N2 = 3; -int64_t sh2[] = { 7, 1, 5 }; - -int64_t ndims[] = { N1, N2 }; -int64_t *shapes[] = { sh1, sh2 }; - -int64_t out[] = { 0, 0, 0, 0 }; -int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -if ( status != 0 ) { - // Handle error... -} -``` - -The function accepts the following arguments: - -- **M**: `[in] int64_t` number of shape arrays. -- **shapes**: `[in] int64_t**` array of shape arrays (dimensions). -- **ndims**: `[in] int64_t*` number of dimensions for each respective shape array. -- **out**: `[out] int64_t*` output shape array. - -```c -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ); -``` - -If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). - -
- - - - - -
- -### Notes - -- Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. - -
- - - - - -
- -### Examples - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main( void ) { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} -``` - -
- - - -
- diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index fa610dc..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,112 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pkg = require( './../package.json' ).name; -var broadcastShapes = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::two_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ] ], - [ [ 3, 2 ], [ 3, 1 ] ], - [ [ 1, 1 ], [ 2, 2 ] ], - [ [ 1 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::three_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::four_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ], [ 8, 1, 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ], [ 1, 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ], [ 1, 1, 2, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ], [ 1 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ], [ 5, 1, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/c/Makefile b/benchmark/c/Makefile deleted file mode 100644 index 5dc545c..0000000 --- a/benchmark/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := benchmark.out - - -# RULES # - -#/ -# Compiles C source files. -# -# @param {string} SOURCE_FILES - list of C source files -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lpthread -lblas`) -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [C_COMPILER] - C compiler -# @param {string} [CFLAGS] - C compiler flags -# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} SOURCE_FILES - list of C source files -# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {(string|void)} LIBRARIES - list of libraries (e.g., `-lpthread -lblas`) -# @param {(string|void)} LIBPATH - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} CC - C compiler -# @param {string} CFLAGS - C compiler flags -# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled benchmarks. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/benchmark/c/benchmark.c b/benchmark/c/benchmark.c deleted file mode 100644 index be62cd5..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,152 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/** -* Benchmark `broadcast_shapes`. -*/ -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "broadcast-shapes" -#define ITERATIONS 1000000 -#define REPEATS 3 - -/** -* Prints the TAP version. -*/ -void print_version() { - printf( "TAP version 13\n" ); -} - -/** -* Prints the TAP summary. -* -* @param total total number of tests -* @param passing total number of passing tests -*/ -void print_summary( int total, int passing ) { - printf( "#\n" ); - printf( "1..%d\n", total ); // TAP plan - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); -} - -/** -* Prints benchmarks results. -* -* @param elapsed elapsed time in seconds -*/ -void print_results( double elapsed ) { - double rate = (double)ITERATIONS / elapsed; - printf( " ---\n" ); - printf( " iterations: %d\n", ITERATIONS ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", rate ); - printf( " ...\n" ); -} - -/** -* Returns a clock time. -* -* @return clock time -*/ -double tic() { - struct timeval now; - gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; -} - -/** -* Generates a random double on the interval [0,1]. -* -* @return random double -*/ -double rand_double() { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark() { - double elapsed; - int8_t status; - double t; - int i; - - int64_t sh1[] = { 8, 1, 6, 1 }; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { 4, 3 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( out[ 0 ] != 8 ) { - printf( "unexpected result\n" ); - } - if ( out[ 1 ] != 7 ) { - printf( "unexpected result\n" ); - } - if ( out[ 2 ] != 6 ) { - printf( "unexpected result\n" ); - } - if ( out[ 3 ] != 5 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Main execution sequence. -*/ -int main( void ) { - double elapsed; - int i; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - for ( i = 0; i < REPEATS; i++ ) { - printf( "# c::native::%s::two_arrays\n", NAME ); - elapsed = benchmark(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", i+1 ); - } - print_summary( REPEATS, REPEATS ); -} diff --git a/branches.md b/branches.md deleted file mode 100644 index 27a33c4..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes" -%% click B href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm \ No newline at end of file diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..3faa0cd --- /dev/null +++ b/browser.js @@ -0,0 +1,3 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map new file mode 100644 index 0000000..aa4b2bb --- /dev/null +++ b/browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"browser.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f1d92f6..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,39 +0,0 @@ - -{{alias}}( shapes ) - Broadcasts array shapes to a single shape. - - Two respective dimensions in two shape arrays are compatible if - - 1. the dimensions are equal. - 2. one dimension is `1`. - - The function returns `null` if provided incompatible shapes (i.e., shapes - which cannot be broadcast with one another). - - Parameters - ---------- - shapes: Array - Array of shape arrays. - - Returns - ------- - out: Array|null - Broadcast shape. - - Examples - -------- - // Compatible shapes: - > var sh1 = [ 8, 1, 6, 1 ]; - > var sh2 = [ 7, 1, 5 ]; - > var sh = {{alias}}( [ sh1, sh2 ] ) - [ 8, 7, 6, 5 ] - - // Incompatible shapes: - > sh1 = [ 3, 2 ]; - > sh1 = [ 2, 3 ]; - > sh = {{alias}}( [ sh1, sh2 ] ) - null - - See Also - -------- - diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts deleted file mode 100644 index f46767d..0000000 --- a/docs/types/index.d.ts +++ /dev/null @@ -1,177 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ArrayLike } from '@stdlib/types/array'; - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param shapes - array shapes -* @returns broadcast shape -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -declare function broadcastShapes( shapes: ArrayLike> ): ArrayLike; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = broadcastShapes; diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 2886539..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 broadcastShapes = require( './index' ); - - -// TESTS // - -// The function returns an array of numbers... -{ - broadcastShapes( [ [ 1, 2 ], [ 2, 2 ] ] ); // $ExpectType ArrayLike -} - -// The compiler throws an error if the function is not provided an array-like object containing array-like objects containing numbers... -{ - broadcastShapes( '5' ); // $ExpectError - broadcastShapes( 5 ); // $ExpectError - broadcastShapes( true ); // $ExpectError - broadcastShapes( false ); // $ExpectError - broadcastShapes( null ); // $ExpectError - broadcastShapes( {} ); // $ExpectError - broadcastShapes( [ '5' ] ); // $ExpectError - broadcastShapes( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - broadcastShapes(); // $ExpectError - broadcastShapes( [ [ 1, 2, 3 ] ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/c/Makefile b/examples/c/Makefile deleted file mode 100644 index 70c91f4..0000000 --- a/examples/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := example.out - - -# RULES # - -#/ -# Compiles source files. -# -# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) -# @param {string} [CFLAGS] - C compiler options -# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) -# @param {string} [SOURCE_FILES] - list of source files -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} CC - C compiler (e.g., `gcc`) -# @param {string} CFLAGS - C compiler options -# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) -# @param {string} SOURCE_FILES - list of source files -# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) -# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled examples. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/examples/c/example.c b/examples/c/example.c deleted file mode 100644 index 4bc54d5..0000000 --- a/examples/c/example.c +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main( void ) { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 28811f9..0000000 --- a/examples/index.js +++ /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. -*/ - -'use strict'; - -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( './../lib' ); - -var shapes; -var out; -var sh; -var i; -var j; - -function shape2string( shape ) { - return lpad( shape.join( ' x ' ), 20, ' ' ); -} - -shapes = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] -]; - -for ( i = 0; i < shapes.length; i++ ) { - sh = shapes[ i ]; - for ( j = 0; j < sh.length; j++ ) { - console.log( shape2string( sh[ j ] ) ); - } - console.log( lpad( '', 20, '-' ) ); - - out = broadcastShapes( sh ); - console.log( shape2string( out )+'\n' ); -} diff --git a/include/stdlib/ndarray/base/broadcast_shapes.h b/include/stdlib/ndarray/base/broadcast_shapes.h deleted file mode 100644 index e23dce1..0000000 --- a/include/stdlib/ndarray/base/broadcast_shapes.h +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#ifndef STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H -#define STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H - -#include - -/* -* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. -*/ -#ifdef __cplusplus -extern "C" { -#endif - -/** -* Broadcasts array shapes to a single shape. -*/ -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H diff --git a/index.js b/index.js new file mode 100644 index 0000000..c1ce4fa --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map new file mode 100644 index 0000000..0c02c0f --- /dev/null +++ b/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 0c9817e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Broadcast array shapes to a single shape. -* -* @module @stdlib/ndarray-base-broadcast-shapes -* -* @example -* var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); -* -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -*/ - -// 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 8558e60..0000000 --- a/lib/main.js +++ /dev/null @@ -1,256 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param {Array} shapes - array of shape arrays -* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`) -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [ 8, 0, 1, 6, 1 ], -* [ 8, 8, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -function broadcastShapes( shapes ) { - var ndims; - var out; - var dim; - var sh; - var n1; - var n2; - var d; - var M; - var N; - var i; - var j; - - M = shapes.length; - out = []; - if ( M === 0 ) { - return out; - } - sh = shapes[ 0 ]; - N = sh.length; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M === 1 ) { - // Need to manually copy to output shape, as shapes could be array-like objects... - for ( i = 0; i < N; i++ ) { - out.push( sh[ i ] ); - } - return out; - } - // Determine the maximum dimensionality... - ndims = [ N ]; - for ( i = 1; i < M; i++ ) { - ndims.push( shapes[ i ].length ); - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Initialize the output array... - for ( i = 0; i < N; i++ ) { - out.push( 0 ); - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim === 1 ) { - dim = d; - continue; - } - if ( d === 1 || dim === d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return null; - } - out[ i ] = dim; - i -= 1; - } - return out; -} - - -// EXPORTS // - -module.exports = broadcastShapes; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 890a937..0000000 --- a/manifest.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "options": {}, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [] - } - ] -} diff --git a/package.json b/package.json index a26ab7b..4b05a44 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,7 @@ "version": "0.0.8", "description": "Broadcast array shapes to a single shape.", "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", - "include": "./include", - "lib": "./lib", - "src": "./src", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "main": "./index.js", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,33 +12,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/types": "^0.0.14", - "@stdlib/utils-library-manifest": "^0.0.8", - "@stdlib/error-tools-fmtprodmsg": "^0.0.2" - }, - "devDependencies": { - "@stdlib/bench": "^0.0.12", - "@stdlib/string-left-pad": "^0.0.9", - "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", "stdtypes", @@ -80,9 +27,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 35a3654..0000000 --- a/src/main.c +++ /dev/null @@ -1,118 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). -* -* - Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. -* -* @param M number of array shapes -* @param shapes pointer to an array containing shape arrays -* @param ndims array containing the number of dimensions for (i.e., length of) each respective shape array -* @param out pointer to output array -* @return status -* -* @example -* #include "stdlib/ndarray/base/broadcast_shapes.h" -* #include -* -* int64_t N1 = 4; -* int64_t sh1[] = { 8, 1, 6, 1 }; -* -* int64_t N2 = 3; -* int64_t sh2[] = { 7, 1, 5 }; -* -* int64_t ndims[] = { N1, N2 }; -* int64_t *shapes[] = { sh1, sh2 }; -* -* int64_t out[] = { 0, 0, 0, 0 }; -* int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -*/ -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ) { - int64_t dim; - int64_t *sh; - int64_t n1; - int64_t n2; - int64_t d; - int64_t N; - int64_t i; - int64_t j; - - if ( M == 0 ) { - return 0; - } - sh = shapes[ 0 ]; - N = ndims[ 0 ]; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M == 1 ) { - for ( i = 0; i < N; i++ ) { - out[ i ] = sh[ i ]; - } - return 0; - } - // Determine the maximum dimensionality... - for ( i = 1; i < M; i++ ) { - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim == 1 ) { - dim = d; - continue; - } - if ( d == 1 || dim == d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return -1; - } - out[ i ] = dim; - i -= 1; - } - return 0; -} diff --git a/stats_browser.html b/stats_browser.html new file mode 100644 index 0000000..d82a0d9 --- /dev/null +++ b/stats_browser.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/stats_node.html b/stats_node.html new file mode 100644 index 0000000..a7e872c --- /dev/null +++ b/stats_node.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 63f703c..0000000 --- a/test/test.js +++ /dev/null @@ -1,230 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var broadcastShapes = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastShapes, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] - ]; - - expected = [ - [ 1, 2 ], - [ 3, 4 ], - [ 5, 6, 7 ], - [ 3, 3 ], - [ 3 ], - [ 3, 2 ], - [ 2, 3 ], - [ 1, 2 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty dims)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 0 ], [ 0, 0 ] ], - [ [ 0, 1 ], [ 0, 0 ] ], - [ [ 1, 0 ], [ 0, 1 ] ], - [ [ 1, 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 1, 0 ] ], - [ [ 1, 1 ], [ 0, 1 ] ], - [ [ 0 ], [ 0, 0 ] ], - [ [ 0 ], [ 0, 1 ] ], - [ [ 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 0 ] ], - [ [ 1 ], [ 0, 1 ] ], - [ [ 1 ], [ 1, 0 ] ], - [ [ 1 ], [ 8, 0 ] ], - [ [ 8, 1, 6, 1 ], [ 0, 1, 5 ] ], - [ [ 8, 0, 6, 1 ], [ 1, 5 ] ] - ]; - - expected = [ - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 1, 0 ], - [ 8, 0 ], - [ 8, 0, 6, 5 ], - [ 8, 0, 6, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (no shapes)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [] - ]; - - expected = [ - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty shapes (i.e., zero-dimensional array broadcasting))', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [] ], - [ [], [] ], - [ [], [], [] ], - [ [], [ 0 ] ], - [ [ 0 ], [] ], - [ [], [ 0, 0 ] ], - [ [ 0, 0 ], [] ], - [ [], [ 1, 0 ] ], - [ [], [ 0, 1 ] ], - [ [], [ 3, 3 ] ], - [ [], [ 3, 3 ], [] ] - ]; - - expected = [ - [], - [], - [], - [ 0 ], - [ 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 3, 3 ], - [ 3, 3 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (single shape)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 7 ] ], - [ [ 1, 1 ] ], - [ [ 5, 6, 1 ] ] - ]; - - expected = [ - [ 7 ], - [ 1, 1 ], - [ 5, 6, 1 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function returns `null` if provided incompatible shapes', function test( t ) { - var actual; - var values; - var i; - - values = [ - [ [ 3 ], [ 4 ] ], - [ [ 2, 3 ], [ 2 ] ], - [ [ 3 ], [ 3 ], [ 4 ] ], - [ [ 1, 3, 4 ], [ 2, 3, 3 ] ], - [ [ 1, 2 ], [ 3, 1 ], [ 3, 2 ], [ 10, 5 ] ], - [ [ 2 ], [ 2, 3 ] ], - [ [ 2 ], [ 2 ], [ 2 ], [ 2 ], [ 3 ], [ 3 ], [ 3 ], [ 3 ] ], - [ [ 9, 0, 9 ], [ 0, 9, 0 ] ], - [ [ 9, 9, 9 ], [ 0, 9, 9 ] ], - [ [ 9, 0, 9 ], [ 9, 9, 9 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 0 ] ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.strictEqual( actual, null, 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); From 7382ed22d9e25ae01bb5d4d21e798ccb7a3d96b8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Jun 2023 02:21:12 +0000 Subject: [PATCH 044/158] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 7abde4e..a26ab7b 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,8 @@ }, "dependencies": { "@stdlib/types": "^0.0.14", - "@stdlib/utils-library-manifest": "^0.0.8" + "@stdlib/utils-library-manifest": "^0.0.8", + "@stdlib/error-tools-fmtprodmsg": "^0.0.2" }, "devDependencies": { "@stdlib/bench": "^0.0.12", @@ -84,4 +85,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From f7b0b284cb2ef6d9ca456478c6fcb45afcff3e43 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Jun 2023 05:34:44 +0000 Subject: [PATCH 045/158] Remove files --- browser.js | 3 - browser.js.map | 1 - index.js | 3 - index.js.map | 1 - stats_browser.html | 6177 -------------------------------------------- stats_node.html | 6177 -------------------------------------------- 6 files changed, 12362 deletions(-) delete mode 100644 browser.js delete mode 100644 browser.js.map delete mode 100644 index.js delete mode 100644 index.js.map delete mode 100644 stats_browser.html delete mode 100644 stats_node.html diff --git a/browser.js b/browser.js deleted file mode 100644 index 3faa0cd..0000000 --- a/browser.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); -//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map deleted file mode 100644 index aa4b2bb..0000000 --- a/browser.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"browser.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/index.js b/index.js deleted file mode 100644 index c1ce4fa..0000000 --- a/index.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); -//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map deleted file mode 100644 index 0c02c0f..0000000 --- a/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/stats_browser.html b/stats_browser.html deleted file mode 100644 index d82a0d9..0000000 --- a/stats_browser.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - diff --git a/stats_node.html b/stats_node.html deleted file mode 100644 index a7e872c..0000000 --- a/stats_node.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 3604a945c5bf7091224509af22681a6a630787b0 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Jun 2023 05:35:21 +0000 Subject: [PATCH 046/158] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 798 --- .github/workflows/publish.yml | 242 - .github/workflows/test.yml | 97 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 178 +- benchmark/benchmark.js | 112 - benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 152 - branches.md | 53 - browser.js | 3 + browser.js.map | 1 + docs/repl.txt | 39 - docs/types/index.d.ts | 177 - docs/types/test.ts | 45 - examples/c/Makefile | 146 - examples/c/example.c | 50 - examples/index.js | 54 - .../stdlib/ndarray/base/broadcast_shapes.h | 40 - index.js | 3 + index.js.map | 1 + lib/index.js | 45 - lib/main.js | 256 - manifest.json | 38 - package.json | 58 +- src/main.c | 118 - stats_browser.html | 6177 +++++++++++++++++ stats_node.html | 6177 +++++++++++++++++ test/test.js | 230 - 47 files changed, 12400 insertions(+), 4981 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.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 branches.md create mode 100644 browser.js create mode 100644 browser.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/index.d.ts delete mode 100644 docs/types/test.ts delete mode 100644 examples/c/Makefile delete mode 100644 examples/c/example.c delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/broadcast_shapes.h create mode 100644 index.js create mode 100644 index.js.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 manifest.json delete mode 100644 src/main.c create mode 100644 stats_browser.html create mode 100644 stats_node.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 487ba0b..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-06-01T01:37:58.538Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 7f004ad..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 8a49110..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 0bff0a0..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 12 * * 5' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 3e8e2db..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,798 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n +``` + +If no recognized module system is present, access bundle contents via the global scope: + +```html + ``` #### broadcastShapes( shapes ) @@ -232,9 +240,14 @@ var sh = broadcastShapes( [ sh1, sh2 ] ); -```javascript -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); +```html + + + + + + + + ```
@@ -275,131 +293,7 @@ for ( i = 0; i < shapes.length; i++ ) { -* * * - -
- -## C APIs - - - -
- -
- - - - - -
- -### Usage - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -``` - -#### stdlib_ndarray_broadcast_shapes( M, \*\*shapes, \*ndims, \*out ) - -Broadcasts array shapes to a single shape. - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -int64_t N1 = 4; -int64_t sh1[] = { 8, 1, 6, 1 }; - -int64_t N2 = 3; -int64_t sh2[] = { 7, 1, 5 }; - -int64_t ndims[] = { N1, N2 }; -int64_t *shapes[] = { sh1, sh2 }; - -int64_t out[] = { 0, 0, 0, 0 }; -int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -if ( status != 0 ) { - // Handle error... -} -``` - -The function accepts the following arguments: - -- **M**: `[in] int64_t` number of shape arrays. -- **shapes**: `[in] int64_t**` array of shape arrays (dimensions). -- **ndims**: `[in] int64_t*` number of dimensions for each respective shape array. -- **out**: `[out] int64_t*` output shape array. - -```c -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ); -``` - -If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). - -
- - - - - -
- -### Notes - -- Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. - -
- - - - - -
- -### Examples - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main( void ) { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} -``` - -
- - - -
- diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index fa610dc..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,112 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pkg = require( './../package.json' ).name; -var broadcastShapes = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::two_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ] ], - [ [ 3, 2 ], [ 3, 1 ] ], - [ [ 1, 1 ], [ 2, 2 ] ], - [ [ 1 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::three_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::four_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ], [ 8, 1, 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ], [ 1, 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ], [ 1, 1, 2, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ], [ 1 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ], [ 5, 1, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/c/Makefile b/benchmark/c/Makefile deleted file mode 100644 index 5dc545c..0000000 --- a/benchmark/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := benchmark.out - - -# RULES # - -#/ -# Compiles C source files. -# -# @param {string} SOURCE_FILES - list of C source files -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lpthread -lblas`) -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [C_COMPILER] - C compiler -# @param {string} [CFLAGS] - C compiler flags -# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} SOURCE_FILES - list of C source files -# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {(string|void)} LIBRARIES - list of libraries (e.g., `-lpthread -lblas`) -# @param {(string|void)} LIBPATH - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} CC - C compiler -# @param {string} CFLAGS - C compiler flags -# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled benchmarks. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/benchmark/c/benchmark.c b/benchmark/c/benchmark.c deleted file mode 100644 index be62cd5..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,152 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/** -* Benchmark `broadcast_shapes`. -*/ -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "broadcast-shapes" -#define ITERATIONS 1000000 -#define REPEATS 3 - -/** -* Prints the TAP version. -*/ -void print_version() { - printf( "TAP version 13\n" ); -} - -/** -* Prints the TAP summary. -* -* @param total total number of tests -* @param passing total number of passing tests -*/ -void print_summary( int total, int passing ) { - printf( "#\n" ); - printf( "1..%d\n", total ); // TAP plan - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); -} - -/** -* Prints benchmarks results. -* -* @param elapsed elapsed time in seconds -*/ -void print_results( double elapsed ) { - double rate = (double)ITERATIONS / elapsed; - printf( " ---\n" ); - printf( " iterations: %d\n", ITERATIONS ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", rate ); - printf( " ...\n" ); -} - -/** -* Returns a clock time. -* -* @return clock time -*/ -double tic() { - struct timeval now; - gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; -} - -/** -* Generates a random double on the interval [0,1]. -* -* @return random double -*/ -double rand_double() { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark() { - double elapsed; - int8_t status; - double t; - int i; - - int64_t sh1[] = { 8, 1, 6, 1 }; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { 4, 3 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( out[ 0 ] != 8 ) { - printf( "unexpected result\n" ); - } - if ( out[ 1 ] != 7 ) { - printf( "unexpected result\n" ); - } - if ( out[ 2 ] != 6 ) { - printf( "unexpected result\n" ); - } - if ( out[ 3 ] != 5 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Main execution sequence. -*/ -int main( void ) { - double elapsed; - int i; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - for ( i = 0; i < REPEATS; i++ ) { - printf( "# c::native::%s::two_arrays\n", NAME ); - elapsed = benchmark(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", i+1 ); - } - print_summary( REPEATS, REPEATS ); -} diff --git a/branches.md b/branches.md deleted file mode 100644 index 27a33c4..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes" -%% click B href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm \ No newline at end of file diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..3faa0cd --- /dev/null +++ b/browser.js @@ -0,0 +1,3 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map new file mode 100644 index 0000000..aa4b2bb --- /dev/null +++ b/browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"browser.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f1d92f6..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,39 +0,0 @@ - -{{alias}}( shapes ) - Broadcasts array shapes to a single shape. - - Two respective dimensions in two shape arrays are compatible if - - 1. the dimensions are equal. - 2. one dimension is `1`. - - The function returns `null` if provided incompatible shapes (i.e., shapes - which cannot be broadcast with one another). - - Parameters - ---------- - shapes: Array - Array of shape arrays. - - Returns - ------- - out: Array|null - Broadcast shape. - - Examples - -------- - // Compatible shapes: - > var sh1 = [ 8, 1, 6, 1 ]; - > var sh2 = [ 7, 1, 5 ]; - > var sh = {{alias}}( [ sh1, sh2 ] ) - [ 8, 7, 6, 5 ] - - // Incompatible shapes: - > sh1 = [ 3, 2 ]; - > sh1 = [ 2, 3 ]; - > sh = {{alias}}( [ sh1, sh2 ] ) - null - - See Also - -------- - diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts deleted file mode 100644 index f46767d..0000000 --- a/docs/types/index.d.ts +++ /dev/null @@ -1,177 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ArrayLike } from '@stdlib/types/array'; - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param shapes - array shapes -* @returns broadcast shape -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -declare function broadcastShapes( shapes: ArrayLike> ): ArrayLike; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = broadcastShapes; diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 2886539..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 broadcastShapes = require( './index' ); - - -// TESTS // - -// The function returns an array of numbers... -{ - broadcastShapes( [ [ 1, 2 ], [ 2, 2 ] ] ); // $ExpectType ArrayLike -} - -// The compiler throws an error if the function is not provided an array-like object containing array-like objects containing numbers... -{ - broadcastShapes( '5' ); // $ExpectError - broadcastShapes( 5 ); // $ExpectError - broadcastShapes( true ); // $ExpectError - broadcastShapes( false ); // $ExpectError - broadcastShapes( null ); // $ExpectError - broadcastShapes( {} ); // $ExpectError - broadcastShapes( [ '5' ] ); // $ExpectError - broadcastShapes( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - broadcastShapes(); // $ExpectError - broadcastShapes( [ [ 1, 2, 3 ] ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/c/Makefile b/examples/c/Makefile deleted file mode 100644 index 70c91f4..0000000 --- a/examples/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := example.out - - -# RULES # - -#/ -# Compiles source files. -# -# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) -# @param {string} [CFLAGS] - C compiler options -# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) -# @param {string} [SOURCE_FILES] - list of source files -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} CC - C compiler (e.g., `gcc`) -# @param {string} CFLAGS - C compiler options -# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) -# @param {string} SOURCE_FILES - list of source files -# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) -# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled examples. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/examples/c/example.c b/examples/c/example.c deleted file mode 100644 index 4bc54d5..0000000 --- a/examples/c/example.c +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main( void ) { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 28811f9..0000000 --- a/examples/index.js +++ /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. -*/ - -'use strict'; - -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( './../lib' ); - -var shapes; -var out; -var sh; -var i; -var j; - -function shape2string( shape ) { - return lpad( shape.join( ' x ' ), 20, ' ' ); -} - -shapes = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] -]; - -for ( i = 0; i < shapes.length; i++ ) { - sh = shapes[ i ]; - for ( j = 0; j < sh.length; j++ ) { - console.log( shape2string( sh[ j ] ) ); - } - console.log( lpad( '', 20, '-' ) ); - - out = broadcastShapes( sh ); - console.log( shape2string( out )+'\n' ); -} diff --git a/include/stdlib/ndarray/base/broadcast_shapes.h b/include/stdlib/ndarray/base/broadcast_shapes.h deleted file mode 100644 index e23dce1..0000000 --- a/include/stdlib/ndarray/base/broadcast_shapes.h +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#ifndef STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H -#define STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H - -#include - -/* -* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. -*/ -#ifdef __cplusplus -extern "C" { -#endif - -/** -* Broadcasts array shapes to a single shape. -*/ -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H diff --git a/index.js b/index.js new file mode 100644 index 0000000..c1ce4fa --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map new file mode 100644 index 0000000..0c02c0f --- /dev/null +++ b/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 0c9817e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Broadcast array shapes to a single shape. -* -* @module @stdlib/ndarray-base-broadcast-shapes -* -* @example -* var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); -* -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -*/ - -// 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 8558e60..0000000 --- a/lib/main.js +++ /dev/null @@ -1,256 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param {Array} shapes - array of shape arrays -* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`) -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [ 8, 0, 1, 6, 1 ], -* [ 8, 8, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -function broadcastShapes( shapes ) { - var ndims; - var out; - var dim; - var sh; - var n1; - var n2; - var d; - var M; - var N; - var i; - var j; - - M = shapes.length; - out = []; - if ( M === 0 ) { - return out; - } - sh = shapes[ 0 ]; - N = sh.length; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M === 1 ) { - // Need to manually copy to output shape, as shapes could be array-like objects... - for ( i = 0; i < N; i++ ) { - out.push( sh[ i ] ); - } - return out; - } - // Determine the maximum dimensionality... - ndims = [ N ]; - for ( i = 1; i < M; i++ ) { - ndims.push( shapes[ i ].length ); - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Initialize the output array... - for ( i = 0; i < N; i++ ) { - out.push( 0 ); - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim === 1 ) { - dim = d; - continue; - } - if ( d === 1 || dim === d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return null; - } - out[ i ] = dim; - i -= 1; - } - return out; -} - - -// EXPORTS // - -module.exports = broadcastShapes; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 890a937..0000000 --- a/manifest.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "options": {}, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [] - } - ] -} diff --git a/package.json b/package.json index a26ab7b..4b05a44 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,7 @@ "version": "0.0.8", "description": "Broadcast array shapes to a single shape.", "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", - "include": "./include", - "lib": "./lib", - "src": "./src", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "main": "./index.js", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,33 +12,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/types": "^0.0.14", - "@stdlib/utils-library-manifest": "^0.0.8", - "@stdlib/error-tools-fmtprodmsg": "^0.0.2" - }, - "devDependencies": { - "@stdlib/bench": "^0.0.12", - "@stdlib/string-left-pad": "^0.0.9", - "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", "stdtypes", @@ -80,9 +27,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 35a3654..0000000 --- a/src/main.c +++ /dev/null @@ -1,118 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). -* -* - Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. -* -* @param M number of array shapes -* @param shapes pointer to an array containing shape arrays -* @param ndims array containing the number of dimensions for (i.e., length of) each respective shape array -* @param out pointer to output array -* @return status -* -* @example -* #include "stdlib/ndarray/base/broadcast_shapes.h" -* #include -* -* int64_t N1 = 4; -* int64_t sh1[] = { 8, 1, 6, 1 }; -* -* int64_t N2 = 3; -* int64_t sh2[] = { 7, 1, 5 }; -* -* int64_t ndims[] = { N1, N2 }; -* int64_t *shapes[] = { sh1, sh2 }; -* -* int64_t out[] = { 0, 0, 0, 0 }; -* int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -*/ -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ) { - int64_t dim; - int64_t *sh; - int64_t n1; - int64_t n2; - int64_t d; - int64_t N; - int64_t i; - int64_t j; - - if ( M == 0 ) { - return 0; - } - sh = shapes[ 0 ]; - N = ndims[ 0 ]; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M == 1 ) { - for ( i = 0; i < N; i++ ) { - out[ i ] = sh[ i ]; - } - return 0; - } - // Determine the maximum dimensionality... - for ( i = 1; i < M; i++ ) { - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim == 1 ) { - dim = d; - continue; - } - if ( d == 1 || dim == d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return -1; - } - out[ i ] = dim; - i -= 1; - } - return 0; -} diff --git a/stats_browser.html b/stats_browser.html new file mode 100644 index 0000000..c86a9a1 --- /dev/null +++ b/stats_browser.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/stats_node.html b/stats_node.html new file mode 100644 index 0000000..ad373f5 --- /dev/null +++ b/stats_node.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 63f703c..0000000 --- a/test/test.js +++ /dev/null @@ -1,230 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var broadcastShapes = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastShapes, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] - ]; - - expected = [ - [ 1, 2 ], - [ 3, 4 ], - [ 5, 6, 7 ], - [ 3, 3 ], - [ 3 ], - [ 3, 2 ], - [ 2, 3 ], - [ 1, 2 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty dims)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 0 ], [ 0, 0 ] ], - [ [ 0, 1 ], [ 0, 0 ] ], - [ [ 1, 0 ], [ 0, 1 ] ], - [ [ 1, 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 1, 0 ] ], - [ [ 1, 1 ], [ 0, 1 ] ], - [ [ 0 ], [ 0, 0 ] ], - [ [ 0 ], [ 0, 1 ] ], - [ [ 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 0 ] ], - [ [ 1 ], [ 0, 1 ] ], - [ [ 1 ], [ 1, 0 ] ], - [ [ 1 ], [ 8, 0 ] ], - [ [ 8, 1, 6, 1 ], [ 0, 1, 5 ] ], - [ [ 8, 0, 6, 1 ], [ 1, 5 ] ] - ]; - - expected = [ - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 1, 0 ], - [ 8, 0 ], - [ 8, 0, 6, 5 ], - [ 8, 0, 6, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (no shapes)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [] - ]; - - expected = [ - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty shapes (i.e., zero-dimensional array broadcasting))', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [] ], - [ [], [] ], - [ [], [], [] ], - [ [], [ 0 ] ], - [ [ 0 ], [] ], - [ [], [ 0, 0 ] ], - [ [ 0, 0 ], [] ], - [ [], [ 1, 0 ] ], - [ [], [ 0, 1 ] ], - [ [], [ 3, 3 ] ], - [ [], [ 3, 3 ], [] ] - ]; - - expected = [ - [], - [], - [], - [ 0 ], - [ 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 3, 3 ], - [ 3, 3 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (single shape)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 7 ] ], - [ [ 1, 1 ] ], - [ [ 5, 6, 1 ] ] - ]; - - expected = [ - [ 7 ], - [ 1, 1 ], - [ 5, 6, 1 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function returns `null` if provided incompatible shapes', function test( t ) { - var actual; - var values; - var i; - - values = [ - [ [ 3 ], [ 4 ] ], - [ [ 2, 3 ], [ 2 ] ], - [ [ 3 ], [ 3 ], [ 4 ] ], - [ [ 1, 3, 4 ], [ 2, 3, 3 ] ], - [ [ 1, 2 ], [ 3, 1 ], [ 3, 2 ], [ 10, 5 ] ], - [ [ 2 ], [ 2, 3 ] ], - [ [ 2 ], [ 2 ], [ 2 ], [ 2 ], [ 3 ], [ 3 ], [ 3 ], [ 3 ] ], - [ [ 9, 0, 9 ], [ 0, 9, 0 ] ], - [ [ 9, 9, 9 ], [ 0, 9, 9 ] ], - [ [ 9, 0, 9 ], [ 9, 9, 9 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 0 ] ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.strictEqual( actual, null, 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); From 37d459326059076f126844d8df6948c1f06c305f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Jul 2023 02:21:10 +0000 Subject: [PATCH 047/158] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 7abde4e..a26ab7b 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,8 @@ }, "dependencies": { "@stdlib/types": "^0.0.14", - "@stdlib/utils-library-manifest": "^0.0.8" + "@stdlib/utils-library-manifest": "^0.0.8", + "@stdlib/error-tools-fmtprodmsg": "^0.0.2" }, "devDependencies": { "@stdlib/bench": "^0.0.12", @@ -84,4 +85,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From ba3297182a624f3f1231ea554d5752cf51c498fb Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Jul 2023 05:29:46 +0000 Subject: [PATCH 048/158] Remove files --- browser.js | 3 - browser.js.map | 1 - index.js | 3 - index.js.map | 1 - stats_browser.html | 6177 -------------------------------------------- stats_node.html | 6177 -------------------------------------------- 6 files changed, 12362 deletions(-) delete mode 100644 browser.js delete mode 100644 browser.js.map delete mode 100644 index.js delete mode 100644 index.js.map delete mode 100644 stats_browser.html delete mode 100644 stats_node.html diff --git a/browser.js b/browser.js deleted file mode 100644 index 3faa0cd..0000000 --- a/browser.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); -//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map deleted file mode 100644 index aa4b2bb..0000000 --- a/browser.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"browser.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/index.js b/index.js deleted file mode 100644 index c1ce4fa..0000000 --- a/index.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); -//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map deleted file mode 100644 index 0c02c0f..0000000 --- a/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/stats_browser.html b/stats_browser.html deleted file mode 100644 index c86a9a1..0000000 --- a/stats_browser.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - diff --git a/stats_node.html b/stats_node.html deleted file mode 100644 index ad373f5..0000000 --- a/stats_node.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From ddf5385c00a3ecab4272ff5f2dfbda029ad63952 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Jul 2023 05:30:36 +0000 Subject: [PATCH 049/158] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 798 --- .github/workflows/publish.yml | 242 - .github/workflows/test.yml | 97 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 178 +- benchmark/benchmark.js | 112 - benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 152 - branches.md | 53 - browser.js | 3 + browser.js.map | 1 + docs/repl.txt | 39 - docs/types/index.d.ts | 177 - docs/types/test.ts | 45 - examples/c/Makefile | 146 - examples/c/example.c | 50 - examples/index.js | 54 - .../stdlib/ndarray/base/broadcast_shapes.h | 40 - index.js | 3 + index.js.map | 1 + lib/index.js | 45 - lib/main.js | 256 - manifest.json | 38 - package.json | 58 +- src/main.c | 118 - stats_browser.html | 6177 +++++++++++++++++ stats_node.html | 6177 +++++++++++++++++ test/test.js | 230 - 47 files changed, 12400 insertions(+), 4981 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.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 branches.md create mode 100644 browser.js create mode 100644 browser.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/index.d.ts delete mode 100644 docs/types/test.ts delete mode 100644 examples/c/Makefile delete mode 100644 examples/c/example.c delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/broadcast_shapes.h create mode 100644 index.js create mode 100644 index.js.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 manifest.json delete mode 100644 src/main.c create mode 100644 stats_browser.html create mode 100644 stats_node.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 b7dea2e..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-07-01T01:38:12.176Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 7f004ad..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 8a49110..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 0bff0a0..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 12 * * 5' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 3e8e2db..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,798 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n +``` + +If no recognized module system is present, access bundle contents via the global scope: + +```html + ``` #### broadcastShapes( shapes ) @@ -232,9 +240,14 @@ var sh = broadcastShapes( [ sh1, sh2 ] ); -```javascript -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); +```html + + + + + + + + ```
@@ -275,131 +293,7 @@ for ( i = 0; i < shapes.length; i++ ) { -* * * - -
- -## C APIs - - - -
- -
- - - - - -
- -### Usage - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -``` - -#### stdlib_ndarray_broadcast_shapes( M, \*\*shapes, \*ndims, \*out ) - -Broadcasts array shapes to a single shape. - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -int64_t N1 = 4; -int64_t sh1[] = { 8, 1, 6, 1 }; - -int64_t N2 = 3; -int64_t sh2[] = { 7, 1, 5 }; - -int64_t ndims[] = { N1, N2 }; -int64_t *shapes[] = { sh1, sh2 }; - -int64_t out[] = { 0, 0, 0, 0 }; -int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -if ( status != 0 ) { - // Handle error... -} -``` - -The function accepts the following arguments: - -- **M**: `[in] int64_t` number of shape arrays. -- **shapes**: `[in] int64_t**` array of shape arrays (dimensions). -- **ndims**: `[in] int64_t*` number of dimensions for each respective shape array. -- **out**: `[out] int64_t*` output shape array. - -```c -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ); -``` - -If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). - -
- - - - - -
- -### Notes - -- Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. - -
- - - - - -
- -### Examples - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main( void ) { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} -``` - -
- - - -
- diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index fa610dc..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,112 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pkg = require( './../package.json' ).name; -var broadcastShapes = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::two_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ] ], - [ [ 3, 2 ], [ 3, 1 ] ], - [ [ 1, 1 ], [ 2, 2 ] ], - [ [ 1 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::three_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::four_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ], [ 8, 1, 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ], [ 1, 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ], [ 1, 1, 2, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ], [ 1 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ], [ 5, 1, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/c/Makefile b/benchmark/c/Makefile deleted file mode 100644 index 5dc545c..0000000 --- a/benchmark/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := benchmark.out - - -# RULES # - -#/ -# Compiles C source files. -# -# @param {string} SOURCE_FILES - list of C source files -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lpthread -lblas`) -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [C_COMPILER] - C compiler -# @param {string} [CFLAGS] - C compiler flags -# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} SOURCE_FILES - list of C source files -# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {(string|void)} LIBRARIES - list of libraries (e.g., `-lpthread -lblas`) -# @param {(string|void)} LIBPATH - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} CC - C compiler -# @param {string} CFLAGS - C compiler flags -# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled benchmarks. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/benchmark/c/benchmark.c b/benchmark/c/benchmark.c deleted file mode 100644 index be62cd5..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,152 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/** -* Benchmark `broadcast_shapes`. -*/ -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "broadcast-shapes" -#define ITERATIONS 1000000 -#define REPEATS 3 - -/** -* Prints the TAP version. -*/ -void print_version() { - printf( "TAP version 13\n" ); -} - -/** -* Prints the TAP summary. -* -* @param total total number of tests -* @param passing total number of passing tests -*/ -void print_summary( int total, int passing ) { - printf( "#\n" ); - printf( "1..%d\n", total ); // TAP plan - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); -} - -/** -* Prints benchmarks results. -* -* @param elapsed elapsed time in seconds -*/ -void print_results( double elapsed ) { - double rate = (double)ITERATIONS / elapsed; - printf( " ---\n" ); - printf( " iterations: %d\n", ITERATIONS ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", rate ); - printf( " ...\n" ); -} - -/** -* Returns a clock time. -* -* @return clock time -*/ -double tic() { - struct timeval now; - gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; -} - -/** -* Generates a random double on the interval [0,1]. -* -* @return random double -*/ -double rand_double() { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark() { - double elapsed; - int8_t status; - double t; - int i; - - int64_t sh1[] = { 8, 1, 6, 1 }; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { 4, 3 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( out[ 0 ] != 8 ) { - printf( "unexpected result\n" ); - } - if ( out[ 1 ] != 7 ) { - printf( "unexpected result\n" ); - } - if ( out[ 2 ] != 6 ) { - printf( "unexpected result\n" ); - } - if ( out[ 3 ] != 5 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Main execution sequence. -*/ -int main( void ) { - double elapsed; - int i; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - for ( i = 0; i < REPEATS; i++ ) { - printf( "# c::native::%s::two_arrays\n", NAME ); - elapsed = benchmark(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", i+1 ); - } - print_summary( REPEATS, REPEATS ); -} diff --git a/branches.md b/branches.md deleted file mode 100644 index 27a33c4..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes" -%% click B href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm \ No newline at end of file diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..3faa0cd --- /dev/null +++ b/browser.js @@ -0,0 +1,3 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map new file mode 100644 index 0000000..aa4b2bb --- /dev/null +++ b/browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"browser.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f1d92f6..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,39 +0,0 @@ - -{{alias}}( shapes ) - Broadcasts array shapes to a single shape. - - Two respective dimensions in two shape arrays are compatible if - - 1. the dimensions are equal. - 2. one dimension is `1`. - - The function returns `null` if provided incompatible shapes (i.e., shapes - which cannot be broadcast with one another). - - Parameters - ---------- - shapes: Array - Array of shape arrays. - - Returns - ------- - out: Array|null - Broadcast shape. - - Examples - -------- - // Compatible shapes: - > var sh1 = [ 8, 1, 6, 1 ]; - > var sh2 = [ 7, 1, 5 ]; - > var sh = {{alias}}( [ sh1, sh2 ] ) - [ 8, 7, 6, 5 ] - - // Incompatible shapes: - > sh1 = [ 3, 2 ]; - > sh1 = [ 2, 3 ]; - > sh = {{alias}}( [ sh1, sh2 ] ) - null - - See Also - -------- - diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts deleted file mode 100644 index f46767d..0000000 --- a/docs/types/index.d.ts +++ /dev/null @@ -1,177 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ArrayLike } from '@stdlib/types/array'; - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param shapes - array shapes -* @returns broadcast shape -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -declare function broadcastShapes( shapes: ArrayLike> ): ArrayLike; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = broadcastShapes; diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 2886539..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 broadcastShapes = require( './index' ); - - -// TESTS // - -// The function returns an array of numbers... -{ - broadcastShapes( [ [ 1, 2 ], [ 2, 2 ] ] ); // $ExpectType ArrayLike -} - -// The compiler throws an error if the function is not provided an array-like object containing array-like objects containing numbers... -{ - broadcastShapes( '5' ); // $ExpectError - broadcastShapes( 5 ); // $ExpectError - broadcastShapes( true ); // $ExpectError - broadcastShapes( false ); // $ExpectError - broadcastShapes( null ); // $ExpectError - broadcastShapes( {} ); // $ExpectError - broadcastShapes( [ '5' ] ); // $ExpectError - broadcastShapes( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - broadcastShapes(); // $ExpectError - broadcastShapes( [ [ 1, 2, 3 ] ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/c/Makefile b/examples/c/Makefile deleted file mode 100644 index 70c91f4..0000000 --- a/examples/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := example.out - - -# RULES # - -#/ -# Compiles source files. -# -# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) -# @param {string} [CFLAGS] - C compiler options -# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) -# @param {string} [SOURCE_FILES] - list of source files -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} CC - C compiler (e.g., `gcc`) -# @param {string} CFLAGS - C compiler options -# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) -# @param {string} SOURCE_FILES - list of source files -# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) -# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled examples. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/examples/c/example.c b/examples/c/example.c deleted file mode 100644 index 4bc54d5..0000000 --- a/examples/c/example.c +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main( void ) { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 28811f9..0000000 --- a/examples/index.js +++ /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. -*/ - -'use strict'; - -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( './../lib' ); - -var shapes; -var out; -var sh; -var i; -var j; - -function shape2string( shape ) { - return lpad( shape.join( ' x ' ), 20, ' ' ); -} - -shapes = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] -]; - -for ( i = 0; i < shapes.length; i++ ) { - sh = shapes[ i ]; - for ( j = 0; j < sh.length; j++ ) { - console.log( shape2string( sh[ j ] ) ); - } - console.log( lpad( '', 20, '-' ) ); - - out = broadcastShapes( sh ); - console.log( shape2string( out )+'\n' ); -} diff --git a/include/stdlib/ndarray/base/broadcast_shapes.h b/include/stdlib/ndarray/base/broadcast_shapes.h deleted file mode 100644 index e23dce1..0000000 --- a/include/stdlib/ndarray/base/broadcast_shapes.h +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#ifndef STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H -#define STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H - -#include - -/* -* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. -*/ -#ifdef __cplusplus -extern "C" { -#endif - -/** -* Broadcasts array shapes to a single shape. -*/ -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H diff --git a/index.js b/index.js new file mode 100644 index 0000000..c1ce4fa --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map new file mode 100644 index 0000000..0c02c0f --- /dev/null +++ b/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 0c9817e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Broadcast array shapes to a single shape. -* -* @module @stdlib/ndarray-base-broadcast-shapes -* -* @example -* var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); -* -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -*/ - -// 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 8558e60..0000000 --- a/lib/main.js +++ /dev/null @@ -1,256 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param {Array} shapes - array of shape arrays -* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`) -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [ 8, 0, 1, 6, 1 ], -* [ 8, 8, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -function broadcastShapes( shapes ) { - var ndims; - var out; - var dim; - var sh; - var n1; - var n2; - var d; - var M; - var N; - var i; - var j; - - M = shapes.length; - out = []; - if ( M === 0 ) { - return out; - } - sh = shapes[ 0 ]; - N = sh.length; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M === 1 ) { - // Need to manually copy to output shape, as shapes could be array-like objects... - for ( i = 0; i < N; i++ ) { - out.push( sh[ i ] ); - } - return out; - } - // Determine the maximum dimensionality... - ndims = [ N ]; - for ( i = 1; i < M; i++ ) { - ndims.push( shapes[ i ].length ); - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Initialize the output array... - for ( i = 0; i < N; i++ ) { - out.push( 0 ); - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim === 1 ) { - dim = d; - continue; - } - if ( d === 1 || dim === d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return null; - } - out[ i ] = dim; - i -= 1; - } - return out; -} - - -// EXPORTS // - -module.exports = broadcastShapes; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 890a937..0000000 --- a/manifest.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "options": {}, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [] - } - ] -} diff --git a/package.json b/package.json index a26ab7b..4b05a44 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,7 @@ "version": "0.0.8", "description": "Broadcast array shapes to a single shape.", "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", - "include": "./include", - "lib": "./lib", - "src": "./src", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "main": "./index.js", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,33 +12,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/types": "^0.0.14", - "@stdlib/utils-library-manifest": "^0.0.8", - "@stdlib/error-tools-fmtprodmsg": "^0.0.2" - }, - "devDependencies": { - "@stdlib/bench": "^0.0.12", - "@stdlib/string-left-pad": "^0.0.9", - "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", "stdtypes", @@ -80,9 +27,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 35a3654..0000000 --- a/src/main.c +++ /dev/null @@ -1,118 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). -* -* - Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. -* -* @param M number of array shapes -* @param shapes pointer to an array containing shape arrays -* @param ndims array containing the number of dimensions for (i.e., length of) each respective shape array -* @param out pointer to output array -* @return status -* -* @example -* #include "stdlib/ndarray/base/broadcast_shapes.h" -* #include -* -* int64_t N1 = 4; -* int64_t sh1[] = { 8, 1, 6, 1 }; -* -* int64_t N2 = 3; -* int64_t sh2[] = { 7, 1, 5 }; -* -* int64_t ndims[] = { N1, N2 }; -* int64_t *shapes[] = { sh1, sh2 }; -* -* int64_t out[] = { 0, 0, 0, 0 }; -* int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -*/ -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ) { - int64_t dim; - int64_t *sh; - int64_t n1; - int64_t n2; - int64_t d; - int64_t N; - int64_t i; - int64_t j; - - if ( M == 0 ) { - return 0; - } - sh = shapes[ 0 ]; - N = ndims[ 0 ]; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M == 1 ) { - for ( i = 0; i < N; i++ ) { - out[ i ] = sh[ i ]; - } - return 0; - } - // Determine the maximum dimensionality... - for ( i = 1; i < M; i++ ) { - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim == 1 ) { - dim = d; - continue; - } - if ( d == 1 || dim == d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return -1; - } - out[ i ] = dim; - i -= 1; - } - return 0; -} diff --git a/stats_browser.html b/stats_browser.html new file mode 100644 index 0000000..d998035 --- /dev/null +++ b/stats_browser.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/stats_node.html b/stats_node.html new file mode 100644 index 0000000..0709fc8 --- /dev/null +++ b/stats_node.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 63f703c..0000000 --- a/test/test.js +++ /dev/null @@ -1,230 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var broadcastShapes = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastShapes, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] - ]; - - expected = [ - [ 1, 2 ], - [ 3, 4 ], - [ 5, 6, 7 ], - [ 3, 3 ], - [ 3 ], - [ 3, 2 ], - [ 2, 3 ], - [ 1, 2 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty dims)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 0 ], [ 0, 0 ] ], - [ [ 0, 1 ], [ 0, 0 ] ], - [ [ 1, 0 ], [ 0, 1 ] ], - [ [ 1, 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 1, 0 ] ], - [ [ 1, 1 ], [ 0, 1 ] ], - [ [ 0 ], [ 0, 0 ] ], - [ [ 0 ], [ 0, 1 ] ], - [ [ 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 0 ] ], - [ [ 1 ], [ 0, 1 ] ], - [ [ 1 ], [ 1, 0 ] ], - [ [ 1 ], [ 8, 0 ] ], - [ [ 8, 1, 6, 1 ], [ 0, 1, 5 ] ], - [ [ 8, 0, 6, 1 ], [ 1, 5 ] ] - ]; - - expected = [ - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 1, 0 ], - [ 8, 0 ], - [ 8, 0, 6, 5 ], - [ 8, 0, 6, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (no shapes)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [] - ]; - - expected = [ - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty shapes (i.e., zero-dimensional array broadcasting))', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [] ], - [ [], [] ], - [ [], [], [] ], - [ [], [ 0 ] ], - [ [ 0 ], [] ], - [ [], [ 0, 0 ] ], - [ [ 0, 0 ], [] ], - [ [], [ 1, 0 ] ], - [ [], [ 0, 1 ] ], - [ [], [ 3, 3 ] ], - [ [], [ 3, 3 ], [] ] - ]; - - expected = [ - [], - [], - [], - [ 0 ], - [ 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 3, 3 ], - [ 3, 3 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (single shape)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 7 ] ], - [ [ 1, 1 ] ], - [ [ 5, 6, 1 ] ] - ]; - - expected = [ - [ 7 ], - [ 1, 1 ], - [ 5, 6, 1 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function returns `null` if provided incompatible shapes', function test( t ) { - var actual; - var values; - var i; - - values = [ - [ [ 3 ], [ 4 ] ], - [ [ 2, 3 ], [ 2 ] ], - [ [ 3 ], [ 3 ], [ 4 ] ], - [ [ 1, 3, 4 ], [ 2, 3, 3 ] ], - [ [ 1, 2 ], [ 3, 1 ], [ 3, 2 ], [ 10, 5 ] ], - [ [ 2 ], [ 2, 3 ] ], - [ [ 2 ], [ 2 ], [ 2 ], [ 2 ], [ 3 ], [ 3 ], [ 3 ], [ 3 ] ], - [ [ 9, 0, 9 ], [ 0, 9, 0 ] ], - [ [ 9, 9, 9 ], [ 0, 9, 9 ] ], - [ [ 9, 0, 9 ], [ 9, 9, 9 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 0 ] ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.strictEqual( actual, null, 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); From 154297ac0091e3087ce928298c2f512e28a4c3e8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Aug 2023 02:30:01 +0000 Subject: [PATCH 050/158] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 7abde4e..a26ab7b 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,8 @@ }, "dependencies": { "@stdlib/types": "^0.0.14", - "@stdlib/utils-library-manifest": "^0.0.8" + "@stdlib/utils-library-manifest": "^0.0.8", + "@stdlib/error-tools-fmtprodmsg": "^0.0.2" }, "devDependencies": { "@stdlib/bench": "^0.0.12", @@ -84,4 +85,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From f2365ae2e181462e520ebb384cddc7bac07fcc16 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Aug 2023 05:51:52 +0000 Subject: [PATCH 051/158] Remove files --- browser.js | 3 - browser.js.map | 1 - index.js | 3 - index.js.map | 1 - stats_browser.html | 6177 -------------------------------------------- stats_node.html | 6177 -------------------------------------------- 6 files changed, 12362 deletions(-) delete mode 100644 browser.js delete mode 100644 browser.js.map delete mode 100644 index.js delete mode 100644 index.js.map delete mode 100644 stats_browser.html delete mode 100644 stats_node.html diff --git a/browser.js b/browser.js deleted file mode 100644 index 3faa0cd..0000000 --- a/browser.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); -//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map deleted file mode 100644 index aa4b2bb..0000000 --- a/browser.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"browser.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/index.js b/index.js deleted file mode 100644 index c1ce4fa..0000000 --- a/index.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); -//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map deleted file mode 100644 index 0c02c0f..0000000 --- a/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/stats_browser.html b/stats_browser.html deleted file mode 100644 index d998035..0000000 --- a/stats_browser.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - diff --git a/stats_node.html b/stats_node.html deleted file mode 100644 index 0709fc8..0000000 --- a/stats_node.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From e85d8d071a32e7313cd502381eb66db38e919a72 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Aug 2023 05:52:43 +0000 Subject: [PATCH 052/158] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 798 --- .github/workflows/publish.yml | 242 - .github/workflows/test.yml | 97 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 178 +- benchmark/benchmark.js | 112 - benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 152 - branches.md | 53 - browser.js | 3 + browser.js.map | 1 + docs/repl.txt | 39 - docs/types/index.d.ts | 177 - docs/types/test.ts | 45 - examples/c/Makefile | 146 - examples/c/example.c | 50 - examples/index.js | 54 - .../stdlib/ndarray/base/broadcast_shapes.h | 40 - index.js | 3 + index.js.map | 1 + lib/index.js | 45 - lib/main.js | 256 - manifest.json | 38 - package.json | 58 +- src/main.c | 118 - stats_browser.html | 6177 +++++++++++++++++ stats_node.html | 6177 +++++++++++++++++ test/test.js | 230 - 47 files changed, 12400 insertions(+), 4981 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.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 branches.md create mode 100644 browser.js create mode 100644 browser.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/index.d.ts delete mode 100644 docs/types/test.ts delete mode 100644 examples/c/Makefile delete mode 100644 examples/c/example.c delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/broadcast_shapes.h create mode 100644 index.js create mode 100644 index.js.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 manifest.json delete mode 100644 src/main.c create mode 100644 stats_browser.html create mode 100644 stats_node.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 e6d63d6..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-08-01T01:41:04.770Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 7f004ad..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 8a49110..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 0bff0a0..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 12 * * 5' - - # 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 334eb59..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,798 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@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 +``` + +If no recognized module system is present, access bundle contents via the global scope: + +```html + ``` #### broadcastShapes( shapes ) @@ -232,9 +240,14 @@ var sh = broadcastShapes( [ sh1, sh2 ] ); -```javascript -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); +```html + + + + + + + + ```
@@ -275,131 +293,7 @@ for ( i = 0; i < shapes.length; i++ ) { -* * * - -
- -## C APIs - - - -
- -
- - - - - -
- -### Usage - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -``` - -#### stdlib_ndarray_broadcast_shapes( M, \*\*shapes, \*ndims, \*out ) - -Broadcasts array shapes to a single shape. - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -int64_t N1 = 4; -int64_t sh1[] = { 8, 1, 6, 1 }; - -int64_t N2 = 3; -int64_t sh2[] = { 7, 1, 5 }; - -int64_t ndims[] = { N1, N2 }; -int64_t *shapes[] = { sh1, sh2 }; - -int64_t out[] = { 0, 0, 0, 0 }; -int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -if ( status != 0 ) { - // Handle error... -} -``` - -The function accepts the following arguments: - -- **M**: `[in] int64_t` number of shape arrays. -- **shapes**: `[in] int64_t**` array of shape arrays (dimensions). -- **ndims**: `[in] int64_t*` number of dimensions for each respective shape array. -- **out**: `[out] int64_t*` output shape array. - -```c -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ); -``` - -If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). - -
- - - - - -
- -### Notes - -- Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. - -
- - - - - -
- -### Examples - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main( void ) { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} -``` - -
- - - -
- diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index fa610dc..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,112 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pkg = require( './../package.json' ).name; -var broadcastShapes = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::two_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ] ], - [ [ 3, 2 ], [ 3, 1 ] ], - [ [ 1, 1 ], [ 2, 2 ] ], - [ [ 1 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::three_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::four_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ], [ 8, 1, 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ], [ 1, 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ], [ 1, 1, 2, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ], [ 1 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ], [ 5, 1, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/c/Makefile b/benchmark/c/Makefile deleted file mode 100644 index 5dc545c..0000000 --- a/benchmark/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := benchmark.out - - -# RULES # - -#/ -# Compiles C source files. -# -# @param {string} SOURCE_FILES - list of C source files -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lpthread -lblas`) -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [C_COMPILER] - C compiler -# @param {string} [CFLAGS] - C compiler flags -# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} SOURCE_FILES - list of C source files -# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {(string|void)} LIBRARIES - list of libraries (e.g., `-lpthread -lblas`) -# @param {(string|void)} LIBPATH - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} CC - C compiler -# @param {string} CFLAGS - C compiler flags -# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled benchmarks. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/benchmark/c/benchmark.c b/benchmark/c/benchmark.c deleted file mode 100644 index be62cd5..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,152 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/** -* Benchmark `broadcast_shapes`. -*/ -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "broadcast-shapes" -#define ITERATIONS 1000000 -#define REPEATS 3 - -/** -* Prints the TAP version. -*/ -void print_version() { - printf( "TAP version 13\n" ); -} - -/** -* Prints the TAP summary. -* -* @param total total number of tests -* @param passing total number of passing tests -*/ -void print_summary( int total, int passing ) { - printf( "#\n" ); - printf( "1..%d\n", total ); // TAP plan - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); -} - -/** -* Prints benchmarks results. -* -* @param elapsed elapsed time in seconds -*/ -void print_results( double elapsed ) { - double rate = (double)ITERATIONS / elapsed; - printf( " ---\n" ); - printf( " iterations: %d\n", ITERATIONS ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", rate ); - printf( " ...\n" ); -} - -/** -* Returns a clock time. -* -* @return clock time -*/ -double tic() { - struct timeval now; - gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; -} - -/** -* Generates a random double on the interval [0,1]. -* -* @return random double -*/ -double rand_double() { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark() { - double elapsed; - int8_t status; - double t; - int i; - - int64_t sh1[] = { 8, 1, 6, 1 }; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { 4, 3 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( out[ 0 ] != 8 ) { - printf( "unexpected result\n" ); - } - if ( out[ 1 ] != 7 ) { - printf( "unexpected result\n" ); - } - if ( out[ 2 ] != 6 ) { - printf( "unexpected result\n" ); - } - if ( out[ 3 ] != 5 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Main execution sequence. -*/ -int main( void ) { - double elapsed; - int i; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - for ( i = 0; i < REPEATS; i++ ) { - printf( "# c::native::%s::two_arrays\n", NAME ); - elapsed = benchmark(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", i+1 ); - } - print_summary( REPEATS, REPEATS ); -} diff --git a/branches.md b/branches.md deleted file mode 100644 index 27a33c4..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes" -%% click B href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm \ No newline at end of file diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..3faa0cd --- /dev/null +++ b/browser.js @@ -0,0 +1,3 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map new file mode 100644 index 0000000..aa4b2bb --- /dev/null +++ b/browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"browser.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f1d92f6..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,39 +0,0 @@ - -{{alias}}( shapes ) - Broadcasts array shapes to a single shape. - - Two respective dimensions in two shape arrays are compatible if - - 1. the dimensions are equal. - 2. one dimension is `1`. - - The function returns `null` if provided incompatible shapes (i.e., shapes - which cannot be broadcast with one another). - - Parameters - ---------- - shapes: Array - Array of shape arrays. - - Returns - ------- - out: Array|null - Broadcast shape. - - Examples - -------- - // Compatible shapes: - > var sh1 = [ 8, 1, 6, 1 ]; - > var sh2 = [ 7, 1, 5 ]; - > var sh = {{alias}}( [ sh1, sh2 ] ) - [ 8, 7, 6, 5 ] - - // Incompatible shapes: - > sh1 = [ 3, 2 ]; - > sh1 = [ 2, 3 ]; - > sh = {{alias}}( [ sh1, sh2 ] ) - null - - See Also - -------- - diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts deleted file mode 100644 index f46767d..0000000 --- a/docs/types/index.d.ts +++ /dev/null @@ -1,177 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ArrayLike } from '@stdlib/types/array'; - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param shapes - array shapes -* @returns broadcast shape -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -declare function broadcastShapes( shapes: ArrayLike> ): ArrayLike; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = broadcastShapes; diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 2886539..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 broadcastShapes = require( './index' ); - - -// TESTS // - -// The function returns an array of numbers... -{ - broadcastShapes( [ [ 1, 2 ], [ 2, 2 ] ] ); // $ExpectType ArrayLike -} - -// The compiler throws an error if the function is not provided an array-like object containing array-like objects containing numbers... -{ - broadcastShapes( '5' ); // $ExpectError - broadcastShapes( 5 ); // $ExpectError - broadcastShapes( true ); // $ExpectError - broadcastShapes( false ); // $ExpectError - broadcastShapes( null ); // $ExpectError - broadcastShapes( {} ); // $ExpectError - broadcastShapes( [ '5' ] ); // $ExpectError - broadcastShapes( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - broadcastShapes(); // $ExpectError - broadcastShapes( [ [ 1, 2, 3 ] ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/c/Makefile b/examples/c/Makefile deleted file mode 100644 index 70c91f4..0000000 --- a/examples/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := example.out - - -# RULES # - -#/ -# Compiles source files. -# -# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) -# @param {string} [CFLAGS] - C compiler options -# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) -# @param {string} [SOURCE_FILES] - list of source files -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} CC - C compiler (e.g., `gcc`) -# @param {string} CFLAGS - C compiler options -# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) -# @param {string} SOURCE_FILES - list of source files -# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) -# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled examples. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/examples/c/example.c b/examples/c/example.c deleted file mode 100644 index 4bc54d5..0000000 --- a/examples/c/example.c +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main( void ) { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 28811f9..0000000 --- a/examples/index.js +++ /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. -*/ - -'use strict'; - -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( './../lib' ); - -var shapes; -var out; -var sh; -var i; -var j; - -function shape2string( shape ) { - return lpad( shape.join( ' x ' ), 20, ' ' ); -} - -shapes = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] -]; - -for ( i = 0; i < shapes.length; i++ ) { - sh = shapes[ i ]; - for ( j = 0; j < sh.length; j++ ) { - console.log( shape2string( sh[ j ] ) ); - } - console.log( lpad( '', 20, '-' ) ); - - out = broadcastShapes( sh ); - console.log( shape2string( out )+'\n' ); -} diff --git a/include/stdlib/ndarray/base/broadcast_shapes.h b/include/stdlib/ndarray/base/broadcast_shapes.h deleted file mode 100644 index e23dce1..0000000 --- a/include/stdlib/ndarray/base/broadcast_shapes.h +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#ifndef STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H -#define STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H - -#include - -/* -* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. -*/ -#ifdef __cplusplus -extern "C" { -#endif - -/** -* Broadcasts array shapes to a single shape. -*/ -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H diff --git a/index.js b/index.js new file mode 100644 index 0000000..c1ce4fa --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map new file mode 100644 index 0000000..0c02c0f --- /dev/null +++ b/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 0c9817e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Broadcast array shapes to a single shape. -* -* @module @stdlib/ndarray-base-broadcast-shapes -* -* @example -* var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); -* -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -*/ - -// 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 8558e60..0000000 --- a/lib/main.js +++ /dev/null @@ -1,256 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param {Array} shapes - array of shape arrays -* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`) -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [ 8, 0, 1, 6, 1 ], -* [ 8, 8, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -function broadcastShapes( shapes ) { - var ndims; - var out; - var dim; - var sh; - var n1; - var n2; - var d; - var M; - var N; - var i; - var j; - - M = shapes.length; - out = []; - if ( M === 0 ) { - return out; - } - sh = shapes[ 0 ]; - N = sh.length; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M === 1 ) { - // Need to manually copy to output shape, as shapes could be array-like objects... - for ( i = 0; i < N; i++ ) { - out.push( sh[ i ] ); - } - return out; - } - // Determine the maximum dimensionality... - ndims = [ N ]; - for ( i = 1; i < M; i++ ) { - ndims.push( shapes[ i ].length ); - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Initialize the output array... - for ( i = 0; i < N; i++ ) { - out.push( 0 ); - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim === 1 ) { - dim = d; - continue; - } - if ( d === 1 || dim === d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return null; - } - out[ i ] = dim; - i -= 1; - } - return out; -} - - -// EXPORTS // - -module.exports = broadcastShapes; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 890a937..0000000 --- a/manifest.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "options": {}, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [] - } - ] -} diff --git a/package.json b/package.json index a26ab7b..4b05a44 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,7 @@ "version": "0.0.8", "description": "Broadcast array shapes to a single shape.", "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", - "include": "./include", - "lib": "./lib", - "src": "./src", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "main": "./index.js", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,33 +12,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/types": "^0.0.14", - "@stdlib/utils-library-manifest": "^0.0.8", - "@stdlib/error-tools-fmtprodmsg": "^0.0.2" - }, - "devDependencies": { - "@stdlib/bench": "^0.0.12", - "@stdlib/string-left-pad": "^0.0.9", - "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", "stdtypes", @@ -80,9 +27,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 35a3654..0000000 --- a/src/main.c +++ /dev/null @@ -1,118 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). -* -* - Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. -* -* @param M number of array shapes -* @param shapes pointer to an array containing shape arrays -* @param ndims array containing the number of dimensions for (i.e., length of) each respective shape array -* @param out pointer to output array -* @return status -* -* @example -* #include "stdlib/ndarray/base/broadcast_shapes.h" -* #include -* -* int64_t N1 = 4; -* int64_t sh1[] = { 8, 1, 6, 1 }; -* -* int64_t N2 = 3; -* int64_t sh2[] = { 7, 1, 5 }; -* -* int64_t ndims[] = { N1, N2 }; -* int64_t *shapes[] = { sh1, sh2 }; -* -* int64_t out[] = { 0, 0, 0, 0 }; -* int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -*/ -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ) { - int64_t dim; - int64_t *sh; - int64_t n1; - int64_t n2; - int64_t d; - int64_t N; - int64_t i; - int64_t j; - - if ( M == 0 ) { - return 0; - } - sh = shapes[ 0 ]; - N = ndims[ 0 ]; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M == 1 ) { - for ( i = 0; i < N; i++ ) { - out[ i ] = sh[ i ]; - } - return 0; - } - // Determine the maximum dimensionality... - for ( i = 1; i < M; i++ ) { - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim == 1 ) { - dim = d; - continue; - } - if ( d == 1 || dim == d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return -1; - } - out[ i ] = dim; - i -= 1; - } - return 0; -} diff --git a/stats_browser.html b/stats_browser.html new file mode 100644 index 0000000..d473e0a --- /dev/null +++ b/stats_browser.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/stats_node.html b/stats_node.html new file mode 100644 index 0000000..fe8f45d --- /dev/null +++ b/stats_node.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 63f703c..0000000 --- a/test/test.js +++ /dev/null @@ -1,230 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var broadcastShapes = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastShapes, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] - ]; - - expected = [ - [ 1, 2 ], - [ 3, 4 ], - [ 5, 6, 7 ], - [ 3, 3 ], - [ 3 ], - [ 3, 2 ], - [ 2, 3 ], - [ 1, 2 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty dims)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 0 ], [ 0, 0 ] ], - [ [ 0, 1 ], [ 0, 0 ] ], - [ [ 1, 0 ], [ 0, 1 ] ], - [ [ 1, 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 1, 0 ] ], - [ [ 1, 1 ], [ 0, 1 ] ], - [ [ 0 ], [ 0, 0 ] ], - [ [ 0 ], [ 0, 1 ] ], - [ [ 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 0 ] ], - [ [ 1 ], [ 0, 1 ] ], - [ [ 1 ], [ 1, 0 ] ], - [ [ 1 ], [ 8, 0 ] ], - [ [ 8, 1, 6, 1 ], [ 0, 1, 5 ] ], - [ [ 8, 0, 6, 1 ], [ 1, 5 ] ] - ]; - - expected = [ - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 1, 0 ], - [ 8, 0 ], - [ 8, 0, 6, 5 ], - [ 8, 0, 6, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (no shapes)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [] - ]; - - expected = [ - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty shapes (i.e., zero-dimensional array broadcasting))', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [] ], - [ [], [] ], - [ [], [], [] ], - [ [], [ 0 ] ], - [ [ 0 ], [] ], - [ [], [ 0, 0 ] ], - [ [ 0, 0 ], [] ], - [ [], [ 1, 0 ] ], - [ [], [ 0, 1 ] ], - [ [], [ 3, 3 ] ], - [ [], [ 3, 3 ], [] ] - ]; - - expected = [ - [], - [], - [], - [ 0 ], - [ 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 3, 3 ], - [ 3, 3 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (single shape)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 7 ] ], - [ [ 1, 1 ] ], - [ [ 5, 6, 1 ] ] - ]; - - expected = [ - [ 7 ], - [ 1, 1 ], - [ 5, 6, 1 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function returns `null` if provided incompatible shapes', function test( t ) { - var actual; - var values; - var i; - - values = [ - [ [ 3 ], [ 4 ] ], - [ [ 2, 3 ], [ 2 ] ], - [ [ 3 ], [ 3 ], [ 4 ] ], - [ [ 1, 3, 4 ], [ 2, 3, 3 ] ], - [ [ 1, 2 ], [ 3, 1 ], [ 3, 2 ], [ 10, 5 ] ], - [ [ 2 ], [ 2, 3 ] ], - [ [ 2 ], [ 2 ], [ 2 ], [ 2 ], [ 3 ], [ 3 ], [ 3 ], [ 3 ] ], - [ [ 9, 0, 9 ], [ 0, 9, 0 ] ], - [ [ 9, 9, 9 ], [ 0, 9, 9 ] ], - [ [ 9, 0, 9 ], [ 9, 9, 9 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 0 ] ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.strictEqual( actual, null, 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); From 8253b4f7dabf674780a4c23b9a888341844894c7 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 22 Sep 2023 23:18:31 +0000 Subject: [PATCH 053/158] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index d7fbca5..3707cb2 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,8 @@ }, "dependencies": { "@stdlib/types": "^0.1.0", - "@stdlib/utils-library-manifest": "^0.1.0" + "@stdlib/utils-library-manifest": "^0.1.0", + "@stdlib/error-tools-fmtprodmsg": "^0.1.0" }, "devDependencies": { "@stdlib/bench": "^0.1.0", @@ -84,4 +85,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From 2885489228d316f9ec696c33a8c6cd6df4b14f0d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 22 Sep 2023 23:59:03 +0000 Subject: [PATCH 054/158] Remove files --- browser.js | 3 - browser.js.map | 1 - index.js | 3 - index.js.map | 1 - stats_browser.html | 6177 -------------------------------------------- stats_node.html | 6177 -------------------------------------------- 6 files changed, 12362 deletions(-) delete mode 100644 browser.js delete mode 100644 browser.js.map delete mode 100644 index.js delete mode 100644 index.js.map delete mode 100644 stats_browser.html delete mode 100644 stats_node.html diff --git a/browser.js b/browser.js deleted file mode 100644 index 3faa0cd..0000000 --- a/browser.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); -//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map deleted file mode 100644 index aa4b2bb..0000000 --- a/browser.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"browser.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/index.js b/index.js deleted file mode 100644 index c1ce4fa..0000000 --- a/index.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); -//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map deleted file mode 100644 index 0c02c0f..0000000 --- a/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/stats_browser.html b/stats_browser.html deleted file mode 100644 index d473e0a..0000000 --- a/stats_browser.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - diff --git a/stats_node.html b/stats_node.html deleted file mode 100644 index fe8f45d..0000000 --- a/stats_node.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 3228558717c4e3b1e7532d06d818413e5295c6ce Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 22 Sep 2023 23:59:48 +0000 Subject: [PATCH 055/158] 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 | 178 +- benchmark/benchmark.js | 112 - benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 152 - branches.md | 53 - browser.js | 3 + browser.js.map | 1 + dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 39 - docs/types/index.d.ts | 177 - docs/types/test.ts | 45 - examples/c/Makefile | 146 - examples/c/example.c | 50 - examples/index.js | 54 - .../stdlib/ndarray/base/broadcast_shapes.h | 40 - index.js | 3 + index.js.map | 1 + lib/index.js | 45 - lib/main.js | 256 - manifest.json | 38 - package.json | 58 +- src/main.c | 118 - stats_browser.html | 6177 +++++++++++++++++ stats_node.html | 6177 +++++++++++++++++ test/test.js | 230 - 50 files changed, 12400 insertions(+), 5015 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.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 branches.md create mode 100644 browser.js create mode 100644 browser.js.map 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/index.d.ts delete mode 100644 docs/types/test.ts delete mode 100644 examples/c/Makefile delete mode 100644 examples/c/example.c delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/broadcast_shapes.h create mode 100644 index.js create mode 100644 index.js.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 manifest.json delete mode 100644 src/main.c create mode 100644 stats_browser.html create mode 100644 stats_node.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 7f004ad..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 8a49110..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 0bff0a0..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 12 * * 5' - - # 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 +``` + +If no recognized module system is present, access bundle contents via the global scope: + +```html + ``` #### broadcastShapes( shapes ) @@ -243,9 +251,14 @@ var sh = broadcastShapes( [ sh1, sh2 ] ); -```javascript -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); +```html + + + + + + + + ```
@@ -286,131 +304,7 @@ for ( i = 0; i < shapes.length; i++ ) { -* * * - -
- -## C APIs - - - -
- -
- - - - - -
- -### Usage - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -``` - -#### stdlib_ndarray_broadcast_shapes( M, \*\*shapes, \*ndims, \*out ) - -Broadcasts array shapes to a single shape. - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -int64_t N1 = 4; -int64_t sh1[] = { 8, 1, 6, 1 }; - -int64_t N2 = 3; -int64_t sh2[] = { 7, 1, 5 }; - -int64_t ndims[] = { N1, N2 }; -int64_t *shapes[] = { sh1, sh2 }; - -int64_t out[] = { 0, 0, 0, 0 }; -int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -if ( status != 0 ) { - // Handle error... -} -``` - -The function accepts the following arguments: - -- **M**: `[in] int64_t` number of shape arrays. -- **shapes**: `[in] int64_t**` array of shape arrays (dimensions). -- **ndims**: `[in] int64_t*` number of dimensions for each respective shape array. -- **out**: `[out] int64_t*` output shape array. - -```c -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ); -``` - -If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). - -
- - - - - -
- -### Notes - -- Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. - -
- - - - - -
- -### Examples - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main( void ) { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} -``` - -
- - - -
- diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index fa610dc..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,112 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pkg = require( './../package.json' ).name; -var broadcastShapes = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::two_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ] ], - [ [ 3, 2 ], [ 3, 1 ] ], - [ [ 1, 1 ], [ 2, 2 ] ], - [ [ 1 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::three_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::four_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ], [ 8, 1, 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ], [ 1, 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ], [ 1, 1, 2, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ], [ 1 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ], [ 5, 1, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/c/Makefile b/benchmark/c/Makefile deleted file mode 100644 index 5dc545c..0000000 --- a/benchmark/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := benchmark.out - - -# RULES # - -#/ -# Compiles C source files. -# -# @param {string} SOURCE_FILES - list of C source files -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lpthread -lblas`) -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [C_COMPILER] - C compiler -# @param {string} [CFLAGS] - C compiler flags -# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} SOURCE_FILES - list of C source files -# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {(string|void)} LIBRARIES - list of libraries (e.g., `-lpthread -lblas`) -# @param {(string|void)} LIBPATH - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} CC - C compiler -# @param {string} CFLAGS - C compiler flags -# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled benchmarks. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/benchmark/c/benchmark.c b/benchmark/c/benchmark.c deleted file mode 100644 index be62cd5..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,152 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/** -* Benchmark `broadcast_shapes`. -*/ -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "broadcast-shapes" -#define ITERATIONS 1000000 -#define REPEATS 3 - -/** -* Prints the TAP version. -*/ -void print_version() { - printf( "TAP version 13\n" ); -} - -/** -* Prints the TAP summary. -* -* @param total total number of tests -* @param passing total number of passing tests -*/ -void print_summary( int total, int passing ) { - printf( "#\n" ); - printf( "1..%d\n", total ); // TAP plan - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); -} - -/** -* Prints benchmarks results. -* -* @param elapsed elapsed time in seconds -*/ -void print_results( double elapsed ) { - double rate = (double)ITERATIONS / elapsed; - printf( " ---\n" ); - printf( " iterations: %d\n", ITERATIONS ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", rate ); - printf( " ...\n" ); -} - -/** -* Returns a clock time. -* -* @return clock time -*/ -double tic() { - struct timeval now; - gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; -} - -/** -* Generates a random double on the interval [0,1]. -* -* @return random double -*/ -double rand_double() { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark() { - double elapsed; - int8_t status; - double t; - int i; - - int64_t sh1[] = { 8, 1, 6, 1 }; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { 4, 3 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( out[ 0 ] != 8 ) { - printf( "unexpected result\n" ); - } - if ( out[ 1 ] != 7 ) { - printf( "unexpected result\n" ); - } - if ( out[ 2 ] != 6 ) { - printf( "unexpected result\n" ); - } - if ( out[ 3 ] != 5 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Main execution sequence. -*/ -int main( void ) { - double elapsed; - int i; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - for ( i = 0; i < REPEATS; i++ ) { - printf( "# c::native::%s::two_arrays\n", NAME ); - elapsed = benchmark(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", i+1 ); - } - print_summary( REPEATS, REPEATS ); -} diff --git a/branches.md b/branches.md deleted file mode 100644 index 27a33c4..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes" -%% click B href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm \ No newline at end of file diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..3faa0cd --- /dev/null +++ b/browser.js @@ -0,0 +1,3 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map new file mode 100644 index 0000000..aa4b2bb --- /dev/null +++ b/browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"browser.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 87ea8b6..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import broadcastShapes from '../docs/types/index'; -export = broadcastShapes; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 625741a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var d=function(t,e){return function(){return e||t((e={exports:{}}).exports,e),e.exports}};var h=d(function(x,c){ -function g(t){var e,n,u,o,s,l,a,f,i,r,v;if(f=t.length,n=[],f===0)return n;if(o=t[0],i=o.length,f===1){for(r=0;ri&&(i=e[r]);for(r=0;r=0;){for(s=e[0]-i+r,s>=0?u=o[s]:u=1,v=1;v=0?a=t[v][l]:a=1,u===1){u=a;continue}if(!(a===1||u===a))return null}n[r]=u,r-=1}return n}c.exports=g -});var m=h();module.exports=m; -/** @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 db2949f..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = broadcastShapes;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast array shapes to a single shape.\n*\n* @module @stdlib/ndarray-base-broadcast-shapes\n*\n* @example\n* var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' );\n*\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\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,cAkLA,SAASC,EAAiBC,EAAS,CAClC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GAFAH,EAAIR,EAAO,OACXE,EAAM,CAAC,EACFM,IAAM,EACV,OAAON,EAMR,GAJAE,EAAKJ,EAAQ,CAAE,EACfS,EAAIL,EAAG,OAGFI,IAAM,EAAI,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAI,KAAME,EAAIM,CAAE,CAAE,EAEnB,OAAOR,CACR,CAGA,IADAD,EAAQ,CAAEQ,CAAE,EACNC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAM,KAAMD,EAAQU,CAAE,EAAE,MAAO,EAC1BT,EAAOS,CAAE,EAAID,IACjBA,EAAIR,EAAOS,CAAE,GAIf,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAI,KAAM,CAAE,EAIb,IADAQ,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IANAL,EAAKJ,EAAO,CAAE,EAAIQ,EAAIC,EACjBL,GAAM,EACVF,EAAMC,EAAIC,CAAG,EAEbF,EAAM,EAEDQ,EAAI,EAAGA,EAAIH,EAAGG,IAAM,CAOzB,GANAL,EAAKL,EAAOU,CAAE,EAAIF,EAAIC,EACjBJ,GAAM,EACVC,EAAIP,EAAQW,CAAE,EAAGL,CAAG,EAEpBC,EAAI,EAEAJ,IAAQ,EAAI,CAChBA,EAAMI,EACN,QACD,CACA,GAAK,EAAAA,IAAM,GAAKJ,IAAQI,GAKxB,OAAO,IACR,CACAL,EAAKQ,CAAE,EAAIP,EACXO,GAAK,CACN,CACA,OAAOR,CACR,CAKAJ,EAAO,QAAUC,ICxNjB,IAAIa,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "broadcastShapes", "shapes", "ndims", "out", "dim", "sh", "n1", "n2", "d", "M", "N", "i", "j", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f1d92f6..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,39 +0,0 @@ - -{{alias}}( shapes ) - Broadcasts array shapes to a single shape. - - Two respective dimensions in two shape arrays are compatible if - - 1. the dimensions are equal. - 2. one dimension is `1`. - - The function returns `null` if provided incompatible shapes (i.e., shapes - which cannot be broadcast with one another). - - Parameters - ---------- - shapes: Array - Array of shape arrays. - - Returns - ------- - out: Array|null - Broadcast shape. - - Examples - -------- - // Compatible shapes: - > var sh1 = [ 8, 1, 6, 1 ]; - > var sh2 = [ 7, 1, 5 ]; - > var sh = {{alias}}( [ sh1, sh2 ] ) - [ 8, 7, 6, 5 ] - - // Incompatible shapes: - > sh1 = [ 3, 2 ]; - > sh1 = [ 2, 3 ]; - > sh = {{alias}}( [ sh1, sh2 ] ) - null - - See Also - -------- - diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts deleted file mode 100644 index f5174e9..0000000 --- a/docs/types/index.d.ts +++ /dev/null @@ -1,177 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ArrayLike } from '@stdlib/types/array'; - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param shapes - array shapes -* @returns broadcast shape -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -declare function broadcastShapes( shapes: ArrayLike> ): ArrayLike; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = broadcastShapes; diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 2886539..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 broadcastShapes = require( './index' ); - - -// TESTS // - -// The function returns an array of numbers... -{ - broadcastShapes( [ [ 1, 2 ], [ 2, 2 ] ] ); // $ExpectType ArrayLike -} - -// The compiler throws an error if the function is not provided an array-like object containing array-like objects containing numbers... -{ - broadcastShapes( '5' ); // $ExpectError - broadcastShapes( 5 ); // $ExpectError - broadcastShapes( true ); // $ExpectError - broadcastShapes( false ); // $ExpectError - broadcastShapes( null ); // $ExpectError - broadcastShapes( {} ); // $ExpectError - broadcastShapes( [ '5' ] ); // $ExpectError - broadcastShapes( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - broadcastShapes(); // $ExpectError - broadcastShapes( [ [ 1, 2, 3 ] ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/c/Makefile b/examples/c/Makefile deleted file mode 100644 index 70c91f4..0000000 --- a/examples/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := example.out - - -# RULES # - -#/ -# Compiles source files. -# -# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) -# @param {string} [CFLAGS] - C compiler options -# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) -# @param {string} [SOURCE_FILES] - list of source files -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} CC - C compiler (e.g., `gcc`) -# @param {string} CFLAGS - C compiler options -# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) -# @param {string} SOURCE_FILES - list of source files -# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) -# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled examples. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/examples/c/example.c b/examples/c/example.c deleted file mode 100644 index 4bc54d5..0000000 --- a/examples/c/example.c +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main( void ) { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 28811f9..0000000 --- a/examples/index.js +++ /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. -*/ - -'use strict'; - -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( './../lib' ); - -var shapes; -var out; -var sh; -var i; -var j; - -function shape2string( shape ) { - return lpad( shape.join( ' x ' ), 20, ' ' ); -} - -shapes = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] -]; - -for ( i = 0; i < shapes.length; i++ ) { - sh = shapes[ i ]; - for ( j = 0; j < sh.length; j++ ) { - console.log( shape2string( sh[ j ] ) ); - } - console.log( lpad( '', 20, '-' ) ); - - out = broadcastShapes( sh ); - console.log( shape2string( out )+'\n' ); -} diff --git a/include/stdlib/ndarray/base/broadcast_shapes.h b/include/stdlib/ndarray/base/broadcast_shapes.h deleted file mode 100644 index e23dce1..0000000 --- a/include/stdlib/ndarray/base/broadcast_shapes.h +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#ifndef STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H -#define STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H - -#include - -/* -* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. -*/ -#ifdef __cplusplus -extern "C" { -#endif - -/** -* Broadcasts array shapes to a single shape. -*/ -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H diff --git a/index.js b/index.js new file mode 100644 index 0000000..c1ce4fa --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map new file mode 100644 index 0000000..0c02c0f --- /dev/null +++ b/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 0c9817e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Broadcast array shapes to a single shape. -* -* @module @stdlib/ndarray-base-broadcast-shapes -* -* @example -* var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); -* -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -*/ - -// 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 8558e60..0000000 --- a/lib/main.js +++ /dev/null @@ -1,256 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param {Array} shapes - array of shape arrays -* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`) -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [ 8, 0, 1, 6, 1 ], -* [ 8, 8, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -function broadcastShapes( shapes ) { - var ndims; - var out; - var dim; - var sh; - var n1; - var n2; - var d; - var M; - var N; - var i; - var j; - - M = shapes.length; - out = []; - if ( M === 0 ) { - return out; - } - sh = shapes[ 0 ]; - N = sh.length; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M === 1 ) { - // Need to manually copy to output shape, as shapes could be array-like objects... - for ( i = 0; i < N; i++ ) { - out.push( sh[ i ] ); - } - return out; - } - // Determine the maximum dimensionality... - ndims = [ N ]; - for ( i = 1; i < M; i++ ) { - ndims.push( shapes[ i ].length ); - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Initialize the output array... - for ( i = 0; i < N; i++ ) { - out.push( 0 ); - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim === 1 ) { - dim = d; - continue; - } - if ( d === 1 || dim === d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return null; - } - out[ i ] = dim; - i -= 1; - } - return out; -} - - -// EXPORTS // - -module.exports = broadcastShapes; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 890a937..0000000 --- a/manifest.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "options": {}, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [] - } - ] -} diff --git a/package.json b/package.json index 3707cb2..f56a223 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,7 @@ "version": "0.1.0", "description": "Broadcast array shapes to a single shape.", "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", - "include": "./include", - "lib": "./lib", - "src": "./src", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "main": "./index.js", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,33 +12,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/types": "^0.1.0", - "@stdlib/utils-library-manifest": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.0" - }, - "devDependencies": { - "@stdlib/bench": "^0.1.0", - "@stdlib/string-left-pad": "^0.0.9", - "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", "stdtypes", @@ -80,9 +27,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 35a3654..0000000 --- a/src/main.c +++ /dev/null @@ -1,118 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). -* -* - Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. -* -* @param M number of array shapes -* @param shapes pointer to an array containing shape arrays -* @param ndims array containing the number of dimensions for (i.e., length of) each respective shape array -* @param out pointer to output array -* @return status -* -* @example -* #include "stdlib/ndarray/base/broadcast_shapes.h" -* #include -* -* int64_t N1 = 4; -* int64_t sh1[] = { 8, 1, 6, 1 }; -* -* int64_t N2 = 3; -* int64_t sh2[] = { 7, 1, 5 }; -* -* int64_t ndims[] = { N1, N2 }; -* int64_t *shapes[] = { sh1, sh2 }; -* -* int64_t out[] = { 0, 0, 0, 0 }; -* int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -*/ -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ) { - int64_t dim; - int64_t *sh; - int64_t n1; - int64_t n2; - int64_t d; - int64_t N; - int64_t i; - int64_t j; - - if ( M == 0 ) { - return 0; - } - sh = shapes[ 0 ]; - N = ndims[ 0 ]; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M == 1 ) { - for ( i = 0; i < N; i++ ) { - out[ i ] = sh[ i ]; - } - return 0; - } - // Determine the maximum dimensionality... - for ( i = 1; i < M; i++ ) { - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim == 1 ) { - dim = d; - continue; - } - if ( d == 1 || dim == d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return -1; - } - out[ i ] = dim; - i -= 1; - } - return 0; -} diff --git a/stats_browser.html b/stats_browser.html new file mode 100644 index 0000000..153ac5e --- /dev/null +++ b/stats_browser.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/stats_node.html b/stats_node.html new file mode 100644 index 0000000..a89f78f --- /dev/null +++ b/stats_node.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 63f703c..0000000 --- a/test/test.js +++ /dev/null @@ -1,230 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var broadcastShapes = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastShapes, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] - ]; - - expected = [ - [ 1, 2 ], - [ 3, 4 ], - [ 5, 6, 7 ], - [ 3, 3 ], - [ 3 ], - [ 3, 2 ], - [ 2, 3 ], - [ 1, 2 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty dims)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 0 ], [ 0, 0 ] ], - [ [ 0, 1 ], [ 0, 0 ] ], - [ [ 1, 0 ], [ 0, 1 ] ], - [ [ 1, 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 1, 0 ] ], - [ [ 1, 1 ], [ 0, 1 ] ], - [ [ 0 ], [ 0, 0 ] ], - [ [ 0 ], [ 0, 1 ] ], - [ [ 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 0 ] ], - [ [ 1 ], [ 0, 1 ] ], - [ [ 1 ], [ 1, 0 ] ], - [ [ 1 ], [ 8, 0 ] ], - [ [ 8, 1, 6, 1 ], [ 0, 1, 5 ] ], - [ [ 8, 0, 6, 1 ], [ 1, 5 ] ] - ]; - - expected = [ - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 1, 0 ], - [ 8, 0 ], - [ 8, 0, 6, 5 ], - [ 8, 0, 6, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (no shapes)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [] - ]; - - expected = [ - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty shapes (i.e., zero-dimensional array broadcasting))', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [] ], - [ [], [] ], - [ [], [], [] ], - [ [], [ 0 ] ], - [ [ 0 ], [] ], - [ [], [ 0, 0 ] ], - [ [ 0, 0 ], [] ], - [ [], [ 1, 0 ] ], - [ [], [ 0, 1 ] ], - [ [], [ 3, 3 ] ], - [ [], [ 3, 3 ], [] ] - ]; - - expected = [ - [], - [], - [], - [ 0 ], - [ 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 3, 3 ], - [ 3, 3 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (single shape)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 7 ] ], - [ [ 1, 1 ] ], - [ [ 5, 6, 1 ] ] - ]; - - expected = [ - [ 7 ], - [ 1, 1 ], - [ 5, 6, 1 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function returns `null` if provided incompatible shapes', function test( t ) { - var actual; - var values; - var i; - - values = [ - [ [ 3 ], [ 4 ] ], - [ [ 2, 3 ], [ 2 ] ], - [ [ 3 ], [ 3 ], [ 4 ] ], - [ [ 1, 3, 4 ], [ 2, 3, 3 ] ], - [ [ 1, 2 ], [ 3, 1 ], [ 3, 2 ], [ 10, 5 ] ], - [ [ 2 ], [ 2, 3 ] ], - [ [ 2 ], [ 2 ], [ 2 ], [ 2 ], [ 3 ], [ 3 ], [ 3 ], [ 3 ] ], - [ [ 9, 0, 9 ], [ 0, 9, 0 ] ], - [ [ 9, 9, 9 ], [ 0, 9, 9 ] ], - [ [ 9, 0, 9 ], [ 9, 9, 9 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 0 ] ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.strictEqual( actual, null, 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); From f65aaf18be2f03ed59bf14bbdc42665c3a5081ea Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 23 Sep 2023 00:23:25 +0000 Subject: [PATCH 056/158] Update README.md for UMD bundle v0.1.0 --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index cf98936..2986b2e 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ limitations under the License. To use in Observable, ```javascript -broadcastShapes = require( 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-shapes@umd/browser.js' ) +broadcastShapes = require( 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-shapes@v0.1.0-umd/browser.js' ) ``` To vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build: @@ -66,7 +66,7 @@ var broadcastShapes = require( 'path/to/vendor/umd/ndarray-base-broadcast-shapes To include the bundle in a webpage, ```html - + ``` If no recognized module system is present, access bundle contents via the global scope: @@ -256,7 +256,7 @@ var sh = broadcastShapes( [ sh1, sh2 ] ); - + + ``` If no recognized module system is present, access bundle contents via the global scope: @@ -256,7 +261,7 @@ var sh = broadcastShapes( [ sh1, sh2 ] ); - + - - - - diff --git a/stats_node.html b/stats_node.html deleted file mode 100644 index a89f78f..0000000 --- a/stats_node.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 897ae3d05af9f468f024d42f170deb17eb88db73 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Oct 2023 20:47:26 +0000 Subject: [PATCH 060/158] 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 | 178 +- benchmark/benchmark.js | 112 - benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 152 - branches.md | 53 - browser.js | 3 + browser.js.map | 1 + dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 39 - docs/types/index.d.ts | 177 - docs/types/test.ts | 45 - examples/c/Makefile | 146 - examples/c/example.c | 50 - examples/index.js | 54 - .../stdlib/ndarray/base/broadcast_shapes.h | 40 - index.js | 3 + index.js.map | 1 + lib/index.js | 45 - lib/main.js | 256 - manifest.json | 38 - package.json | 58 +- src/main.c | 118 - stats_browser.html | 6177 +++++++++++++++++ stats_node.html | 6177 +++++++++++++++++ test/dist/test.js | 230 - test/test.js | 230 - 52 files changed, 12400 insertions(+), 5304 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.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 branches.md create mode 100644 browser.js create mode 100644 browser.js.map 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/index.d.ts delete mode 100644 docs/types/test.ts delete mode 100644 examples/c/Makefile delete mode 100644 examples/c/example.c delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/broadcast_shapes.h create mode 100644 index.js create mode 100644 index.js.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 manifest.json delete mode 100644 src/main.c create mode 100644 stats_browser.html create mode 100644 stats_node.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 66d5e13..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-10-01T01:22:20.573Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 7f004ad..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 a07d970..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 b69deb3..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: '0 12 * * 5' - - # 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 +``` + +If no recognized module system is present, access bundle contents via the global scope: + +```html + ``` #### broadcastShapes( shapes ) @@ -243,9 +251,14 @@ var sh = broadcastShapes( [ sh1, sh2 ] ); -```javascript -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); +```html + + + + + + + + ```
@@ -286,131 +304,7 @@ for ( i = 0; i < shapes.length; i++ ) { -* * * - -
- -## C APIs - - - -
- -
- - - - - -
- -### Usage - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -``` - -#### stdlib_ndarray_broadcast_shapes( M, \*\*shapes, \*ndims, \*out ) - -Broadcasts array shapes to a single shape. - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -int64_t N1 = 4; -int64_t sh1[] = { 8, 1, 6, 1 }; - -int64_t N2 = 3; -int64_t sh2[] = { 7, 1, 5 }; - -int64_t ndims[] = { N1, N2 }; -int64_t *shapes[] = { sh1, sh2 }; - -int64_t out[] = { 0, 0, 0, 0 }; -int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -if ( status != 0 ) { - // Handle error... -} -``` - -The function accepts the following arguments: - -- **M**: `[in] int64_t` number of shape arrays. -- **shapes**: `[in] int64_t**` array of shape arrays (dimensions). -- **ndims**: `[in] int64_t*` number of dimensions for each respective shape array. -- **out**: `[out] int64_t*` output shape array. - -```c -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ); -``` - -If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). - -
- - - - - -
- -### Notes - -- Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. - -
- - - - - -
- -### Examples - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main( void ) { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} -``` - -
- - - -
- diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index fa610dc..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,112 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pkg = require( './../package.json' ).name; -var broadcastShapes = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::two_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ] ], - [ [ 3, 2 ], [ 3, 1 ] ], - [ [ 1, 1 ], [ 2, 2 ] ], - [ [ 1 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::three_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::four_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ], [ 8, 1, 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ], [ 1, 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ], [ 1, 1, 2, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ], [ 1 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ], [ 5, 1, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/c/Makefile b/benchmark/c/Makefile deleted file mode 100644 index 5dc545c..0000000 --- a/benchmark/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := benchmark.out - - -# RULES # - -#/ -# Compiles C source files. -# -# @param {string} SOURCE_FILES - list of C source files -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lpthread -lblas`) -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [C_COMPILER] - C compiler -# @param {string} [CFLAGS] - C compiler flags -# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} SOURCE_FILES - list of C source files -# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {(string|void)} LIBRARIES - list of libraries (e.g., `-lpthread -lblas`) -# @param {(string|void)} LIBPATH - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} CC - C compiler -# @param {string} CFLAGS - C compiler flags -# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled benchmarks. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/benchmark/c/benchmark.c b/benchmark/c/benchmark.c deleted file mode 100644 index be62cd5..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,152 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/** -* Benchmark `broadcast_shapes`. -*/ -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "broadcast-shapes" -#define ITERATIONS 1000000 -#define REPEATS 3 - -/** -* Prints the TAP version. -*/ -void print_version() { - printf( "TAP version 13\n" ); -} - -/** -* Prints the TAP summary. -* -* @param total total number of tests -* @param passing total number of passing tests -*/ -void print_summary( int total, int passing ) { - printf( "#\n" ); - printf( "1..%d\n", total ); // TAP plan - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); -} - -/** -* Prints benchmarks results. -* -* @param elapsed elapsed time in seconds -*/ -void print_results( double elapsed ) { - double rate = (double)ITERATIONS / elapsed; - printf( " ---\n" ); - printf( " iterations: %d\n", ITERATIONS ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", rate ); - printf( " ...\n" ); -} - -/** -* Returns a clock time. -* -* @return clock time -*/ -double tic() { - struct timeval now; - gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; -} - -/** -* Generates a random double on the interval [0,1]. -* -* @return random double -*/ -double rand_double() { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark() { - double elapsed; - int8_t status; - double t; - int i; - - int64_t sh1[] = { 8, 1, 6, 1 }; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { 4, 3 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( out[ 0 ] != 8 ) { - printf( "unexpected result\n" ); - } - if ( out[ 1 ] != 7 ) { - printf( "unexpected result\n" ); - } - if ( out[ 2 ] != 6 ) { - printf( "unexpected result\n" ); - } - if ( out[ 3 ] != 5 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Main execution sequence. -*/ -int main( void ) { - double elapsed; - int i; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - for ( i = 0; i < REPEATS; i++ ) { - printf( "# c::native::%s::two_arrays\n", NAME ); - elapsed = benchmark(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", i+1 ); - } - print_summary( REPEATS, REPEATS ); -} diff --git a/branches.md b/branches.md deleted file mode 100644 index 27a33c4..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes" -%% click B href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm \ No newline at end of file diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..3faa0cd --- /dev/null +++ b/browser.js @@ -0,0 +1,3 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map new file mode 100644 index 0000000..aa4b2bb --- /dev/null +++ b/browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"browser.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 87ea8b6..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import broadcastShapes from '../docs/types/index'; -export = broadcastShapes; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 625741a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var d=function(t,e){return function(){return e||t((e={exports:{}}).exports,e),e.exports}};var h=d(function(x,c){ -function g(t){var e,n,u,o,s,l,a,f,i,r,v;if(f=t.length,n=[],f===0)return n;if(o=t[0],i=o.length,f===1){for(r=0;ri&&(i=e[r]);for(r=0;r=0;){for(s=e[0]-i+r,s>=0?u=o[s]:u=1,v=1;v=0?a=t[v][l]:a=1,u===1){u=a;continue}if(!(a===1||u===a))return null}n[r]=u,r-=1}return n}c.exports=g -});var m=h();module.exports=m; -/** @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 db2949f..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = broadcastShapes;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast array shapes to a single shape.\n*\n* @module @stdlib/ndarray-base-broadcast-shapes\n*\n* @example\n* var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' );\n*\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\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,cAkLA,SAASC,EAAiBC,EAAS,CAClC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GAFAH,EAAIR,EAAO,OACXE,EAAM,CAAC,EACFM,IAAM,EACV,OAAON,EAMR,GAJAE,EAAKJ,EAAQ,CAAE,EACfS,EAAIL,EAAG,OAGFI,IAAM,EAAI,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAI,KAAME,EAAIM,CAAE,CAAE,EAEnB,OAAOR,CACR,CAGA,IADAD,EAAQ,CAAEQ,CAAE,EACNC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAM,KAAMD,EAAQU,CAAE,EAAE,MAAO,EAC1BT,EAAOS,CAAE,EAAID,IACjBA,EAAIR,EAAOS,CAAE,GAIf,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAI,KAAM,CAAE,EAIb,IADAQ,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IANAL,EAAKJ,EAAO,CAAE,EAAIQ,EAAIC,EACjBL,GAAM,EACVF,EAAMC,EAAIC,CAAG,EAEbF,EAAM,EAEDQ,EAAI,EAAGA,EAAIH,EAAGG,IAAM,CAOzB,GANAL,EAAKL,EAAOU,CAAE,EAAIF,EAAIC,EACjBJ,GAAM,EACVC,EAAIP,EAAQW,CAAE,EAAGL,CAAG,EAEpBC,EAAI,EAEAJ,IAAQ,EAAI,CAChBA,EAAMI,EACN,QACD,CACA,GAAK,EAAAA,IAAM,GAAKJ,IAAQI,GAKxB,OAAO,IACR,CACAL,EAAKQ,CAAE,EAAIP,EACXO,GAAK,CACN,CACA,OAAOR,CACR,CAKAJ,EAAO,QAAUC,ICxNjB,IAAIa,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "broadcastShapes", "shapes", "ndims", "out", "dim", "sh", "n1", "n2", "d", "M", "N", "i", "j", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f1d92f6..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,39 +0,0 @@ - -{{alias}}( shapes ) - Broadcasts array shapes to a single shape. - - Two respective dimensions in two shape arrays are compatible if - - 1. the dimensions are equal. - 2. one dimension is `1`. - - The function returns `null` if provided incompatible shapes (i.e., shapes - which cannot be broadcast with one another). - - Parameters - ---------- - shapes: Array - Array of shape arrays. - - Returns - ------- - out: Array|null - Broadcast shape. - - Examples - -------- - // Compatible shapes: - > var sh1 = [ 8, 1, 6, 1 ]; - > var sh2 = [ 7, 1, 5 ]; - > var sh = {{alias}}( [ sh1, sh2 ] ) - [ 8, 7, 6, 5 ] - - // Incompatible shapes: - > sh1 = [ 3, 2 ]; - > sh1 = [ 2, 3 ]; - > sh = {{alias}}( [ sh1, sh2 ] ) - null - - See Also - -------- - diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts deleted file mode 100644 index f5174e9..0000000 --- a/docs/types/index.d.ts +++ /dev/null @@ -1,177 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ArrayLike } from '@stdlib/types/array'; - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param shapes - array shapes -* @returns broadcast shape -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -declare function broadcastShapes( shapes: ArrayLike> ): ArrayLike; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = broadcastShapes; diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 2886539..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 broadcastShapes = require( './index' ); - - -// TESTS // - -// The function returns an array of numbers... -{ - broadcastShapes( [ [ 1, 2 ], [ 2, 2 ] ] ); // $ExpectType ArrayLike -} - -// The compiler throws an error if the function is not provided an array-like object containing array-like objects containing numbers... -{ - broadcastShapes( '5' ); // $ExpectError - broadcastShapes( 5 ); // $ExpectError - broadcastShapes( true ); // $ExpectError - broadcastShapes( false ); // $ExpectError - broadcastShapes( null ); // $ExpectError - broadcastShapes( {} ); // $ExpectError - broadcastShapes( [ '5' ] ); // $ExpectError - broadcastShapes( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - broadcastShapes(); // $ExpectError - broadcastShapes( [ [ 1, 2, 3 ] ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/c/Makefile b/examples/c/Makefile deleted file mode 100644 index 70c91f4..0000000 --- a/examples/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := example.out - - -# RULES # - -#/ -# Compiles source files. -# -# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) -# @param {string} [CFLAGS] - C compiler options -# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) -# @param {string} [SOURCE_FILES] - list of source files -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} CC - C compiler (e.g., `gcc`) -# @param {string} CFLAGS - C compiler options -# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) -# @param {string} SOURCE_FILES - list of source files -# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) -# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled examples. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/examples/c/example.c b/examples/c/example.c deleted file mode 100644 index 4bc54d5..0000000 --- a/examples/c/example.c +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main( void ) { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 28811f9..0000000 --- a/examples/index.js +++ /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. -*/ - -'use strict'; - -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( './../lib' ); - -var shapes; -var out; -var sh; -var i; -var j; - -function shape2string( shape ) { - return lpad( shape.join( ' x ' ), 20, ' ' ); -} - -shapes = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] -]; - -for ( i = 0; i < shapes.length; i++ ) { - sh = shapes[ i ]; - for ( j = 0; j < sh.length; j++ ) { - console.log( shape2string( sh[ j ] ) ); - } - console.log( lpad( '', 20, '-' ) ); - - out = broadcastShapes( sh ); - console.log( shape2string( out )+'\n' ); -} diff --git a/include/stdlib/ndarray/base/broadcast_shapes.h b/include/stdlib/ndarray/base/broadcast_shapes.h deleted file mode 100644 index e23dce1..0000000 --- a/include/stdlib/ndarray/base/broadcast_shapes.h +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#ifndef STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H -#define STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H - -#include - -/* -* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. -*/ -#ifdef __cplusplus -extern "C" { -#endif - -/** -* Broadcasts array shapes to a single shape. -*/ -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H diff --git a/index.js b/index.js new file mode 100644 index 0000000..c1ce4fa --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map new file mode 100644 index 0000000..0c02c0f --- /dev/null +++ b/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 0c9817e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Broadcast array shapes to a single shape. -* -* @module @stdlib/ndarray-base-broadcast-shapes -* -* @example -* var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); -* -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -*/ - -// 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 8558e60..0000000 --- a/lib/main.js +++ /dev/null @@ -1,256 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param {Array} shapes - array of shape arrays -* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`) -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [ 8, 0, 1, 6, 1 ], -* [ 8, 8, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -function broadcastShapes( shapes ) { - var ndims; - var out; - var dim; - var sh; - var n1; - var n2; - var d; - var M; - var N; - var i; - var j; - - M = shapes.length; - out = []; - if ( M === 0 ) { - return out; - } - sh = shapes[ 0 ]; - N = sh.length; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M === 1 ) { - // Need to manually copy to output shape, as shapes could be array-like objects... - for ( i = 0; i < N; i++ ) { - out.push( sh[ i ] ); - } - return out; - } - // Determine the maximum dimensionality... - ndims = [ N ]; - for ( i = 1; i < M; i++ ) { - ndims.push( shapes[ i ].length ); - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Initialize the output array... - for ( i = 0; i < N; i++ ) { - out.push( 0 ); - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim === 1 ) { - dim = d; - continue; - } - if ( d === 1 || dim === d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return null; - } - out[ i ] = dim; - i -= 1; - } - return out; -} - - -// EXPORTS // - -module.exports = broadcastShapes; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 890a937..0000000 --- a/manifest.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "options": {}, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [] - } - ] -} diff --git a/package.json b/package.json index 74854b0..f56a223 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,7 @@ "version": "0.1.0", "description": "Broadcast array shapes to a single shape.", "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", - "include": "./include", - "lib": "./lib", - "src": "./src", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "main": "./index.js", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,33 +12,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/types": "^0.1.0", - "@stdlib/utils-library-manifest": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.0" - }, - "devDependencies": { - "@stdlib/bench": "^0.1.0", - "@stdlib/string-left-pad": "^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", "stdtypes", @@ -80,9 +27,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 35a3654..0000000 --- a/src/main.c +++ /dev/null @@ -1,118 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). -* -* - Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. -* -* @param M number of array shapes -* @param shapes pointer to an array containing shape arrays -* @param ndims array containing the number of dimensions for (i.e., length of) each respective shape array -* @param out pointer to output array -* @return status -* -* @example -* #include "stdlib/ndarray/base/broadcast_shapes.h" -* #include -* -* int64_t N1 = 4; -* int64_t sh1[] = { 8, 1, 6, 1 }; -* -* int64_t N2 = 3; -* int64_t sh2[] = { 7, 1, 5 }; -* -* int64_t ndims[] = { N1, N2 }; -* int64_t *shapes[] = { sh1, sh2 }; -* -* int64_t out[] = { 0, 0, 0, 0 }; -* int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -*/ -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ) { - int64_t dim; - int64_t *sh; - int64_t n1; - int64_t n2; - int64_t d; - int64_t N; - int64_t i; - int64_t j; - - if ( M == 0 ) { - return 0; - } - sh = shapes[ 0 ]; - N = ndims[ 0 ]; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M == 1 ) { - for ( i = 0; i < N; i++ ) { - out[ i ] = sh[ i ]; - } - return 0; - } - // Determine the maximum dimensionality... - for ( i = 1; i < M; i++ ) { - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim == 1 ) { - dim = d; - continue; - } - if ( d == 1 || dim == d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return -1; - } - out[ i ] = dim; - i -= 1; - } - return 0; -} diff --git a/stats_browser.html b/stats_browser.html new file mode 100644 index 0000000..09a4785 --- /dev/null +++ b/stats_browser.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/stats_node.html b/stats_node.html new file mode 100644 index 0000000..ae54572 --- /dev/null +++ b/stats_node.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index 4740dac..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,230 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var broadcastShapes = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastShapes, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] - ]; - - expected = [ - [ 1, 2 ], - [ 3, 4 ], - [ 5, 6, 7 ], - [ 3, 3 ], - [ 3 ], - [ 3, 2 ], - [ 2, 3 ], - [ 1, 2 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty dims)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 0 ], [ 0, 0 ] ], - [ [ 0, 1 ], [ 0, 0 ] ], - [ [ 1, 0 ], [ 0, 1 ] ], - [ [ 1, 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 1, 0 ] ], - [ [ 1, 1 ], [ 0, 1 ] ], - [ [ 0 ], [ 0, 0 ] ], - [ [ 0 ], [ 0, 1 ] ], - [ [ 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 0 ] ], - [ [ 1 ], [ 0, 1 ] ], - [ [ 1 ], [ 1, 0 ] ], - [ [ 1 ], [ 8, 0 ] ], - [ [ 8, 1, 6, 1 ], [ 0, 1, 5 ] ], - [ [ 8, 0, 6, 1 ], [ 1, 5 ] ] - ]; - - expected = [ - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 1, 0 ], - [ 8, 0 ], - [ 8, 0, 6, 5 ], - [ 8, 0, 6, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (no shapes)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [] - ]; - - expected = [ - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty shapes (i.e., zero-dimensional array broadcasting))', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [] ], - [ [], [] ], - [ [], [], [] ], - [ [], [ 0 ] ], - [ [ 0 ], [] ], - [ [], [ 0, 0 ] ], - [ [ 0, 0 ], [] ], - [ [], [ 1, 0 ] ], - [ [], [ 0, 1 ] ], - [ [], [ 3, 3 ] ], - [ [], [ 3, 3 ], [] ] - ]; - - expected = [ - [], - [], - [], - [ 0 ], - [ 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 3, 3 ], - [ 3, 3 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (single shape)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 7 ] ], - [ [ 1, 1 ] ], - [ [ 5, 6, 1 ] ] - ]; - - expected = [ - [ 7 ], - [ 1, 1 ], - [ 5, 6, 1 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function returns `null` if provided incompatible shapes', function test( t ) { - var actual; - var values; - var i; - - values = [ - [ [ 3 ], [ 4 ] ], - [ [ 2, 3 ], [ 2 ] ], - [ [ 3 ], [ 3 ], [ 4 ] ], - [ [ 1, 3, 4 ], [ 2, 3, 3 ] ], - [ [ 1, 2 ], [ 3, 1 ], [ 3, 2 ], [ 10, 5 ] ], - [ [ 2 ], [ 2, 3 ] ], - [ [ 2 ], [ 2 ], [ 2 ], [ 2 ], [ 3 ], [ 3 ], [ 3 ], [ 3 ] ], - [ [ 9, 0, 9 ], [ 0, 9, 0 ] ], - [ [ 9, 9, 9 ], [ 0, 9, 9 ] ], - [ [ 9, 0, 9 ], [ 9, 9, 9 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 0 ] ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.strictEqual( actual, null, 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 63f703c..0000000 --- a/test/test.js +++ /dev/null @@ -1,230 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var broadcastShapes = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastShapes, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] - ]; - - expected = [ - [ 1, 2 ], - [ 3, 4 ], - [ 5, 6, 7 ], - [ 3, 3 ], - [ 3 ], - [ 3, 2 ], - [ 2, 3 ], - [ 1, 2 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty dims)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 0 ], [ 0, 0 ] ], - [ [ 0, 1 ], [ 0, 0 ] ], - [ [ 1, 0 ], [ 0, 1 ] ], - [ [ 1, 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 1, 0 ] ], - [ [ 1, 1 ], [ 0, 1 ] ], - [ [ 0 ], [ 0, 0 ] ], - [ [ 0 ], [ 0, 1 ] ], - [ [ 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 0 ] ], - [ [ 1 ], [ 0, 1 ] ], - [ [ 1 ], [ 1, 0 ] ], - [ [ 1 ], [ 8, 0 ] ], - [ [ 8, 1, 6, 1 ], [ 0, 1, 5 ] ], - [ [ 8, 0, 6, 1 ], [ 1, 5 ] ] - ]; - - expected = [ - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 1, 0 ], - [ 8, 0 ], - [ 8, 0, 6, 5 ], - [ 8, 0, 6, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (no shapes)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [] - ]; - - expected = [ - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty shapes (i.e., zero-dimensional array broadcasting))', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [] ], - [ [], [] ], - [ [], [], [] ], - [ [], [ 0 ] ], - [ [ 0 ], [] ], - [ [], [ 0, 0 ] ], - [ [ 0, 0 ], [] ], - [ [], [ 1, 0 ] ], - [ [], [ 0, 1 ] ], - [ [], [ 3, 3 ] ], - [ [], [ 3, 3 ], [] ] - ]; - - expected = [ - [], - [], - [], - [ 0 ], - [ 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 3, 3 ], - [ 3, 3 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (single shape)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 7 ] ], - [ [ 1, 1 ] ], - [ [ 5, 6, 1 ] ] - ]; - - expected = [ - [ 7 ], - [ 1, 1 ], - [ 5, 6, 1 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function returns `null` if provided incompatible shapes', function test( t ) { - var actual; - var values; - var i; - - values = [ - [ [ 3 ], [ 4 ] ], - [ [ 2, 3 ], [ 2 ] ], - [ [ 3 ], [ 3 ], [ 4 ] ], - [ [ 1, 3, 4 ], [ 2, 3, 3 ] ], - [ [ 1, 2 ], [ 3, 1 ], [ 3, 2 ], [ 10, 5 ] ], - [ [ 2 ], [ 2, 3 ] ], - [ [ 2 ], [ 2 ], [ 2 ], [ 2 ], [ 3 ], [ 3 ], [ 3 ], [ 3 ] ], - [ [ 9, 0, 9 ], [ 0, 9, 0 ] ], - [ [ 9, 9, 9 ], [ 0, 9, 9 ] ], - [ [ 9, 0, 9 ], [ 9, 9, 9 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 0 ] ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.strictEqual( actual, null, 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); From d9bb874a57e07345b34d12aa8fd1ae7e56aaf484 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 4 Oct 2023 02:34:22 +0000 Subject: [PATCH 061/158] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 8681aa8..bd62ab1 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,8 @@ }, "dependencies": { "@stdlib/types": "^0.1.0", - "@stdlib/utils-library-manifest": "^0.1.1" + "@stdlib/utils-library-manifest": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1" }, "devDependencies": { "@stdlib/bench": "^0.1.0", @@ -84,4 +85,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From 7c63cb81d700208e6c431bdc36bd69ab57b5725d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 4 Oct 2023 12:07:20 +0000 Subject: [PATCH 062/158] Remove files --- browser.js | 3 - browser.js.map | 1 - index.js | 3 - index.js.map | 1 - stats_browser.html | 6177 -------------------------------------------- stats_node.html | 6177 -------------------------------------------- 6 files changed, 12362 deletions(-) delete mode 100644 browser.js delete mode 100644 browser.js.map delete mode 100644 index.js delete mode 100644 index.js.map delete mode 100644 stats_browser.html delete mode 100644 stats_node.html diff --git a/browser.js b/browser.js deleted file mode 100644 index 3faa0cd..0000000 --- a/browser.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); -//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map deleted file mode 100644 index aa4b2bb..0000000 --- a/browser.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"browser.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/index.js b/index.js deleted file mode 100644 index c1ce4fa..0000000 --- a/index.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); -//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map deleted file mode 100644 index 0c02c0f..0000000 --- a/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/stats_browser.html b/stats_browser.html deleted file mode 100644 index 09a4785..0000000 --- a/stats_browser.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - diff --git a/stats_node.html b/stats_node.html deleted file mode 100644 index ae54572..0000000 --- a/stats_node.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 949118226f10e3fc759c5c2f5e6f6805e767b74e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 4 Oct 2023 12:08:08 +0000 Subject: [PATCH 063/158] 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 | 178 +- benchmark/benchmark.js | 112 - benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 152 - branches.md | 53 - browser.js | 3 + browser.js.map | 1 + dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 39 - docs/types/index.d.ts | 177 - docs/types/test.ts | 45 - examples/c/Makefile | 146 - examples/c/example.c | 50 - examples/index.js | 54 - .../stdlib/ndarray/base/broadcast_shapes.h | 40 - index.js | 3 + index.js.map | 1 + lib/index.js | 45 - lib/main.js | 256 - manifest.json | 38 - package.json | 58 +- src/main.c | 118 - stats_browser.html | 6177 +++++++++++++++++ stats_node.html | 6177 +++++++++++++++++ test/dist/test.js | 230 - test/test.js | 230 - 51 files changed, 12400 insertions(+), 5303 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.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 branches.md create mode 100644 browser.js create mode 100644 browser.js.map 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/index.d.ts delete mode 100644 docs/types/test.ts delete mode 100644 examples/c/Makefile delete mode 100644 examples/c/example.c delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/broadcast_shapes.h create mode 100644 index.js create mode 100644 index.js.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 manifest.json delete mode 100644 src/main.c create mode 100644 stats_browser.html create mode 100644 stats_node.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 7f004ad..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 a07d970..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 b69deb3..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: '0 12 * * 5' - - # 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 +``` + +If no recognized module system is present, access bundle contents via the global scope: + +```html + ``` #### broadcastShapes( shapes ) @@ -243,9 +251,14 @@ var sh = broadcastShapes( [ sh1, sh2 ] ); -```javascript -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); +```html + + + + + + + + ```
@@ -286,131 +304,7 @@ for ( i = 0; i < shapes.length; i++ ) { -* * * - -
- -## C APIs - - - -
- -
- - - - - -
- -### Usage - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -``` - -#### stdlib_ndarray_broadcast_shapes( M, \*\*shapes, \*ndims, \*out ) - -Broadcasts array shapes to a single shape. - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -int64_t N1 = 4; -int64_t sh1[] = { 8, 1, 6, 1 }; - -int64_t N2 = 3; -int64_t sh2[] = { 7, 1, 5 }; - -int64_t ndims[] = { N1, N2 }; -int64_t *shapes[] = { sh1, sh2 }; - -int64_t out[] = { 0, 0, 0, 0 }; -int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -if ( status != 0 ) { - // Handle error... -} -``` - -The function accepts the following arguments: - -- **M**: `[in] int64_t` number of shape arrays. -- **shapes**: `[in] int64_t**` array of shape arrays (dimensions). -- **ndims**: `[in] int64_t*` number of dimensions for each respective shape array. -- **out**: `[out] int64_t*` output shape array. - -```c -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ); -``` - -If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). - -
- - - - - -
- -### Notes - -- Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. - -
- - - - - -
- -### Examples - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main( void ) { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} -``` - -
- - - -
- diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index fa610dc..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,112 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pkg = require( './../package.json' ).name; -var broadcastShapes = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::two_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ] ], - [ [ 3, 2 ], [ 3, 1 ] ], - [ [ 1, 1 ], [ 2, 2 ] ], - [ [ 1 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::three_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::four_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ], [ 8, 1, 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ], [ 1, 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ], [ 1, 1, 2, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ], [ 1 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ], [ 5, 1, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/c/Makefile b/benchmark/c/Makefile deleted file mode 100644 index 5dc545c..0000000 --- a/benchmark/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := benchmark.out - - -# RULES # - -#/ -# Compiles C source files. -# -# @param {string} SOURCE_FILES - list of C source files -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lpthread -lblas`) -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [C_COMPILER] - C compiler -# @param {string} [CFLAGS] - C compiler flags -# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} SOURCE_FILES - list of C source files -# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {(string|void)} LIBRARIES - list of libraries (e.g., `-lpthread -lblas`) -# @param {(string|void)} LIBPATH - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} CC - C compiler -# @param {string} CFLAGS - C compiler flags -# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled benchmarks. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/benchmark/c/benchmark.c b/benchmark/c/benchmark.c deleted file mode 100644 index be62cd5..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,152 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/** -* Benchmark `broadcast_shapes`. -*/ -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "broadcast-shapes" -#define ITERATIONS 1000000 -#define REPEATS 3 - -/** -* Prints the TAP version. -*/ -void print_version() { - printf( "TAP version 13\n" ); -} - -/** -* Prints the TAP summary. -* -* @param total total number of tests -* @param passing total number of passing tests -*/ -void print_summary( int total, int passing ) { - printf( "#\n" ); - printf( "1..%d\n", total ); // TAP plan - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); -} - -/** -* Prints benchmarks results. -* -* @param elapsed elapsed time in seconds -*/ -void print_results( double elapsed ) { - double rate = (double)ITERATIONS / elapsed; - printf( " ---\n" ); - printf( " iterations: %d\n", ITERATIONS ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", rate ); - printf( " ...\n" ); -} - -/** -* Returns a clock time. -* -* @return clock time -*/ -double tic() { - struct timeval now; - gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; -} - -/** -* Generates a random double on the interval [0,1]. -* -* @return random double -*/ -double rand_double() { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark() { - double elapsed; - int8_t status; - double t; - int i; - - int64_t sh1[] = { 8, 1, 6, 1 }; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { 4, 3 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( out[ 0 ] != 8 ) { - printf( "unexpected result\n" ); - } - if ( out[ 1 ] != 7 ) { - printf( "unexpected result\n" ); - } - if ( out[ 2 ] != 6 ) { - printf( "unexpected result\n" ); - } - if ( out[ 3 ] != 5 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Main execution sequence. -*/ -int main( void ) { - double elapsed; - int i; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - for ( i = 0; i < REPEATS; i++ ) { - printf( "# c::native::%s::two_arrays\n", NAME ); - elapsed = benchmark(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", i+1 ); - } - print_summary( REPEATS, REPEATS ); -} diff --git a/branches.md b/branches.md deleted file mode 100644 index 27a33c4..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes" -%% click B href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm \ No newline at end of file diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..3faa0cd --- /dev/null +++ b/browser.js @@ -0,0 +1,3 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map new file mode 100644 index 0000000..aa4b2bb --- /dev/null +++ b/browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"browser.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 87ea8b6..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import broadcastShapes from '../docs/types/index'; -export = broadcastShapes; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 625741a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var d=function(t,e){return function(){return e||t((e={exports:{}}).exports,e),e.exports}};var h=d(function(x,c){ -function g(t){var e,n,u,o,s,l,a,f,i,r,v;if(f=t.length,n=[],f===0)return n;if(o=t[0],i=o.length,f===1){for(r=0;ri&&(i=e[r]);for(r=0;r=0;){for(s=e[0]-i+r,s>=0?u=o[s]:u=1,v=1;v=0?a=t[v][l]:a=1,u===1){u=a;continue}if(!(a===1||u===a))return null}n[r]=u,r-=1}return n}c.exports=g -});var m=h();module.exports=m; -/** @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 db2949f..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = broadcastShapes;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast array shapes to a single shape.\n*\n* @module @stdlib/ndarray-base-broadcast-shapes\n*\n* @example\n* var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' );\n*\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\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,cAkLA,SAASC,EAAiBC,EAAS,CAClC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GAFAH,EAAIR,EAAO,OACXE,EAAM,CAAC,EACFM,IAAM,EACV,OAAON,EAMR,GAJAE,EAAKJ,EAAQ,CAAE,EACfS,EAAIL,EAAG,OAGFI,IAAM,EAAI,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAI,KAAME,EAAIM,CAAE,CAAE,EAEnB,OAAOR,CACR,CAGA,IADAD,EAAQ,CAAEQ,CAAE,EACNC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAM,KAAMD,EAAQU,CAAE,EAAE,MAAO,EAC1BT,EAAOS,CAAE,EAAID,IACjBA,EAAIR,EAAOS,CAAE,GAIf,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAI,KAAM,CAAE,EAIb,IADAQ,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IANAL,EAAKJ,EAAO,CAAE,EAAIQ,EAAIC,EACjBL,GAAM,EACVF,EAAMC,EAAIC,CAAG,EAEbF,EAAM,EAEDQ,EAAI,EAAGA,EAAIH,EAAGG,IAAM,CAOzB,GANAL,EAAKL,EAAOU,CAAE,EAAIF,EAAIC,EACjBJ,GAAM,EACVC,EAAIP,EAAQW,CAAE,EAAGL,CAAG,EAEpBC,EAAI,EAEAJ,IAAQ,EAAI,CAChBA,EAAMI,EACN,QACD,CACA,GAAK,EAAAA,IAAM,GAAKJ,IAAQI,GAKxB,OAAO,IACR,CACAL,EAAKQ,CAAE,EAAIP,EACXO,GAAK,CACN,CACA,OAAOR,CACR,CAKAJ,EAAO,QAAUC,ICxNjB,IAAIa,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "broadcastShapes", "shapes", "ndims", "out", "dim", "sh", "n1", "n2", "d", "M", "N", "i", "j", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f1d92f6..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,39 +0,0 @@ - -{{alias}}( shapes ) - Broadcasts array shapes to a single shape. - - Two respective dimensions in two shape arrays are compatible if - - 1. the dimensions are equal. - 2. one dimension is `1`. - - The function returns `null` if provided incompatible shapes (i.e., shapes - which cannot be broadcast with one another). - - Parameters - ---------- - shapes: Array - Array of shape arrays. - - Returns - ------- - out: Array|null - Broadcast shape. - - Examples - -------- - // Compatible shapes: - > var sh1 = [ 8, 1, 6, 1 ]; - > var sh2 = [ 7, 1, 5 ]; - > var sh = {{alias}}( [ sh1, sh2 ] ) - [ 8, 7, 6, 5 ] - - // Incompatible shapes: - > sh1 = [ 3, 2 ]; - > sh1 = [ 2, 3 ]; - > sh = {{alias}}( [ sh1, sh2 ] ) - null - - See Also - -------- - diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts deleted file mode 100644 index f5174e9..0000000 --- a/docs/types/index.d.ts +++ /dev/null @@ -1,177 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ArrayLike } from '@stdlib/types/array'; - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param shapes - array shapes -* @returns broadcast shape -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -declare function broadcastShapes( shapes: ArrayLike> ): ArrayLike; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = broadcastShapes; diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 2886539..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 broadcastShapes = require( './index' ); - - -// TESTS // - -// The function returns an array of numbers... -{ - broadcastShapes( [ [ 1, 2 ], [ 2, 2 ] ] ); // $ExpectType ArrayLike -} - -// The compiler throws an error if the function is not provided an array-like object containing array-like objects containing numbers... -{ - broadcastShapes( '5' ); // $ExpectError - broadcastShapes( 5 ); // $ExpectError - broadcastShapes( true ); // $ExpectError - broadcastShapes( false ); // $ExpectError - broadcastShapes( null ); // $ExpectError - broadcastShapes( {} ); // $ExpectError - broadcastShapes( [ '5' ] ); // $ExpectError - broadcastShapes( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - broadcastShapes(); // $ExpectError - broadcastShapes( [ [ 1, 2, 3 ] ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/c/Makefile b/examples/c/Makefile deleted file mode 100644 index 70c91f4..0000000 --- a/examples/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := example.out - - -# RULES # - -#/ -# Compiles source files. -# -# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) -# @param {string} [CFLAGS] - C compiler options -# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) -# @param {string} [SOURCE_FILES] - list of source files -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} CC - C compiler (e.g., `gcc`) -# @param {string} CFLAGS - C compiler options -# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) -# @param {string} SOURCE_FILES - list of source files -# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) -# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled examples. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/examples/c/example.c b/examples/c/example.c deleted file mode 100644 index 4bc54d5..0000000 --- a/examples/c/example.c +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main( void ) { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 28811f9..0000000 --- a/examples/index.js +++ /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. -*/ - -'use strict'; - -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( './../lib' ); - -var shapes; -var out; -var sh; -var i; -var j; - -function shape2string( shape ) { - return lpad( shape.join( ' x ' ), 20, ' ' ); -} - -shapes = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] -]; - -for ( i = 0; i < shapes.length; i++ ) { - sh = shapes[ i ]; - for ( j = 0; j < sh.length; j++ ) { - console.log( shape2string( sh[ j ] ) ); - } - console.log( lpad( '', 20, '-' ) ); - - out = broadcastShapes( sh ); - console.log( shape2string( out )+'\n' ); -} diff --git a/include/stdlib/ndarray/base/broadcast_shapes.h b/include/stdlib/ndarray/base/broadcast_shapes.h deleted file mode 100644 index e23dce1..0000000 --- a/include/stdlib/ndarray/base/broadcast_shapes.h +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#ifndef STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H -#define STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H - -#include - -/* -* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. -*/ -#ifdef __cplusplus -extern "C" { -#endif - -/** -* Broadcasts array shapes to a single shape. -*/ -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H diff --git a/index.js b/index.js new file mode 100644 index 0000000..c1ce4fa --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map new file mode 100644 index 0000000..0c02c0f --- /dev/null +++ b/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 0c9817e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Broadcast array shapes to a single shape. -* -* @module @stdlib/ndarray-base-broadcast-shapes -* -* @example -* var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); -* -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -*/ - -// 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 8558e60..0000000 --- a/lib/main.js +++ /dev/null @@ -1,256 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param {Array} shapes - array of shape arrays -* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`) -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [ 8, 0, 1, 6, 1 ], -* [ 8, 8, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -function broadcastShapes( shapes ) { - var ndims; - var out; - var dim; - var sh; - var n1; - var n2; - var d; - var M; - var N; - var i; - var j; - - M = shapes.length; - out = []; - if ( M === 0 ) { - return out; - } - sh = shapes[ 0 ]; - N = sh.length; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M === 1 ) { - // Need to manually copy to output shape, as shapes could be array-like objects... - for ( i = 0; i < N; i++ ) { - out.push( sh[ i ] ); - } - return out; - } - // Determine the maximum dimensionality... - ndims = [ N ]; - for ( i = 1; i < M; i++ ) { - ndims.push( shapes[ i ].length ); - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Initialize the output array... - for ( i = 0; i < N; i++ ) { - out.push( 0 ); - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim === 1 ) { - dim = d; - continue; - } - if ( d === 1 || dim === d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return null; - } - out[ i ] = dim; - i -= 1; - } - return out; -} - - -// EXPORTS // - -module.exports = broadcastShapes; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 890a937..0000000 --- a/manifest.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "options": {}, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [] - } - ] -} diff --git a/package.json b/package.json index bd62ab1..b48d2f6 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,7 @@ "version": "0.1.1", "description": "Broadcast array shapes to a single shape.", "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", - "include": "./include", - "lib": "./lib", - "src": "./src", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "main": "./index.js", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,33 +12,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/types": "^0.1.0", - "@stdlib/utils-library-manifest": "^0.1.1", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1" - }, - "devDependencies": { - "@stdlib/bench": "^0.1.0", - "@stdlib/string-left-pad": "^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", "stdtypes", @@ -80,9 +27,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 35a3654..0000000 --- a/src/main.c +++ /dev/null @@ -1,118 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). -* -* - Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. -* -* @param M number of array shapes -* @param shapes pointer to an array containing shape arrays -* @param ndims array containing the number of dimensions for (i.e., length of) each respective shape array -* @param out pointer to output array -* @return status -* -* @example -* #include "stdlib/ndarray/base/broadcast_shapes.h" -* #include -* -* int64_t N1 = 4; -* int64_t sh1[] = { 8, 1, 6, 1 }; -* -* int64_t N2 = 3; -* int64_t sh2[] = { 7, 1, 5 }; -* -* int64_t ndims[] = { N1, N2 }; -* int64_t *shapes[] = { sh1, sh2 }; -* -* int64_t out[] = { 0, 0, 0, 0 }; -* int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -*/ -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ) { - int64_t dim; - int64_t *sh; - int64_t n1; - int64_t n2; - int64_t d; - int64_t N; - int64_t i; - int64_t j; - - if ( M == 0 ) { - return 0; - } - sh = shapes[ 0 ]; - N = ndims[ 0 ]; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M == 1 ) { - for ( i = 0; i < N; i++ ) { - out[ i ] = sh[ i ]; - } - return 0; - } - // Determine the maximum dimensionality... - for ( i = 1; i < M; i++ ) { - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim == 1 ) { - dim = d; - continue; - } - if ( d == 1 || dim == d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return -1; - } - out[ i ] = dim; - i -= 1; - } - return 0; -} diff --git a/stats_browser.html b/stats_browser.html new file mode 100644 index 0000000..d121144 --- /dev/null +++ b/stats_browser.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/stats_node.html b/stats_node.html new file mode 100644 index 0000000..adcc77a --- /dev/null +++ b/stats_node.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index 4740dac..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,230 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var broadcastShapes = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastShapes, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] - ]; - - expected = [ - [ 1, 2 ], - [ 3, 4 ], - [ 5, 6, 7 ], - [ 3, 3 ], - [ 3 ], - [ 3, 2 ], - [ 2, 3 ], - [ 1, 2 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty dims)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 0 ], [ 0, 0 ] ], - [ [ 0, 1 ], [ 0, 0 ] ], - [ [ 1, 0 ], [ 0, 1 ] ], - [ [ 1, 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 1, 0 ] ], - [ [ 1, 1 ], [ 0, 1 ] ], - [ [ 0 ], [ 0, 0 ] ], - [ [ 0 ], [ 0, 1 ] ], - [ [ 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 0 ] ], - [ [ 1 ], [ 0, 1 ] ], - [ [ 1 ], [ 1, 0 ] ], - [ [ 1 ], [ 8, 0 ] ], - [ [ 8, 1, 6, 1 ], [ 0, 1, 5 ] ], - [ [ 8, 0, 6, 1 ], [ 1, 5 ] ] - ]; - - expected = [ - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 1, 0 ], - [ 8, 0 ], - [ 8, 0, 6, 5 ], - [ 8, 0, 6, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (no shapes)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [] - ]; - - expected = [ - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty shapes (i.e., zero-dimensional array broadcasting))', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [] ], - [ [], [] ], - [ [], [], [] ], - [ [], [ 0 ] ], - [ [ 0 ], [] ], - [ [], [ 0, 0 ] ], - [ [ 0, 0 ], [] ], - [ [], [ 1, 0 ] ], - [ [], [ 0, 1 ] ], - [ [], [ 3, 3 ] ], - [ [], [ 3, 3 ], [] ] - ]; - - expected = [ - [], - [], - [], - [ 0 ], - [ 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 3, 3 ], - [ 3, 3 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (single shape)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 7 ] ], - [ [ 1, 1 ] ], - [ [ 5, 6, 1 ] ] - ]; - - expected = [ - [ 7 ], - [ 1, 1 ], - [ 5, 6, 1 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function returns `null` if provided incompatible shapes', function test( t ) { - var actual; - var values; - var i; - - values = [ - [ [ 3 ], [ 4 ] ], - [ [ 2, 3 ], [ 2 ] ], - [ [ 3 ], [ 3 ], [ 4 ] ], - [ [ 1, 3, 4 ], [ 2, 3, 3 ] ], - [ [ 1, 2 ], [ 3, 1 ], [ 3, 2 ], [ 10, 5 ] ], - [ [ 2 ], [ 2, 3 ] ], - [ [ 2 ], [ 2 ], [ 2 ], [ 2 ], [ 3 ], [ 3 ], [ 3 ], [ 3 ] ], - [ [ 9, 0, 9 ], [ 0, 9, 0 ] ], - [ [ 9, 9, 9 ], [ 0, 9, 9 ] ], - [ [ 9, 0, 9 ], [ 9, 9, 9 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 0 ] ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.strictEqual( actual, null, 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 63f703c..0000000 --- a/test/test.js +++ /dev/null @@ -1,230 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var broadcastShapes = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastShapes, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] - ]; - - expected = [ - [ 1, 2 ], - [ 3, 4 ], - [ 5, 6, 7 ], - [ 3, 3 ], - [ 3 ], - [ 3, 2 ], - [ 2, 3 ], - [ 1, 2 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty dims)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 0 ], [ 0, 0 ] ], - [ [ 0, 1 ], [ 0, 0 ] ], - [ [ 1, 0 ], [ 0, 1 ] ], - [ [ 1, 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 1, 0 ] ], - [ [ 1, 1 ], [ 0, 1 ] ], - [ [ 0 ], [ 0, 0 ] ], - [ [ 0 ], [ 0, 1 ] ], - [ [ 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 0 ] ], - [ [ 1 ], [ 0, 1 ] ], - [ [ 1 ], [ 1, 0 ] ], - [ [ 1 ], [ 8, 0 ] ], - [ [ 8, 1, 6, 1 ], [ 0, 1, 5 ] ], - [ [ 8, 0, 6, 1 ], [ 1, 5 ] ] - ]; - - expected = [ - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 1, 0 ], - [ 8, 0 ], - [ 8, 0, 6, 5 ], - [ 8, 0, 6, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (no shapes)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [] - ]; - - expected = [ - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty shapes (i.e., zero-dimensional array broadcasting))', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [] ], - [ [], [] ], - [ [], [], [] ], - [ [], [ 0 ] ], - [ [ 0 ], [] ], - [ [], [ 0, 0 ] ], - [ [ 0, 0 ], [] ], - [ [], [ 1, 0 ] ], - [ [], [ 0, 1 ] ], - [ [], [ 3, 3 ] ], - [ [], [ 3, 3 ], [] ] - ]; - - expected = [ - [], - [], - [], - [ 0 ], - [ 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 3, 3 ], - [ 3, 3 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (single shape)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 7 ] ], - [ [ 1, 1 ] ], - [ [ 5, 6, 1 ] ] - ]; - - expected = [ - [ 7 ], - [ 1, 1 ], - [ 5, 6, 1 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function returns `null` if provided incompatible shapes', function test( t ) { - var actual; - var values; - var i; - - values = [ - [ [ 3 ], [ 4 ] ], - [ [ 2, 3 ], [ 2 ] ], - [ [ 3 ], [ 3 ], [ 4 ] ], - [ [ 1, 3, 4 ], [ 2, 3, 3 ] ], - [ [ 1, 2 ], [ 3, 1 ], [ 3, 2 ], [ 10, 5 ] ], - [ [ 2 ], [ 2, 3 ] ], - [ [ 2 ], [ 2 ], [ 2 ], [ 2 ], [ 3 ], [ 3 ], [ 3 ], [ 3 ] ], - [ [ 9, 0, 9 ], [ 0, 9, 0 ] ], - [ [ 9, 9, 9 ], [ 0, 9, 9 ] ], - [ [ 9, 0, 9 ], [ 9, 9, 9 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 0 ] ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.strictEqual( actual, null, 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); From 0124ea78da7bc410d4f528268fe048d1f2e5e6bf Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 4 Oct 2023 16:00:17 +0000 Subject: [PATCH 064/158] Update README.md for UMD bundle v0.1.1 --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 3518d16..1c2bba1 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ limitations under the License. To use in Observable, ```javascript -broadcastShapes = require( 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-shapes@umd/browser.js' ) +broadcastShapes = require( 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-shapes@v0.1.1-umd/browser.js' ) ``` To vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build: @@ -66,7 +66,7 @@ var broadcastShapes = require( 'path/to/vendor/umd/ndarray-base-broadcast-shapes To include the bundle in a webpage, ```html - + ``` If no recognized module system is present, access bundle contents via the global scope: @@ -256,7 +256,7 @@ var sh = broadcastShapes( [ sh1, sh2 ] ); - + + ``` If no recognized module system is present, access bundle contents via the global scope: @@ -256,7 +261,7 @@ var sh = broadcastShapes( [ sh1, sh2 ] ); - + - - - - diff --git a/stats_node.html b/stats_node.html deleted file mode 100644 index adcc77a..0000000 --- a/stats_node.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 9acff12c0d0cace91a94e9d47ef51cce0110f524 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 5 Oct 2023 22:33:30 +0000 Subject: [PATCH 068/158] 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 | 178 +- benchmark/benchmark.js | 112 - benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 152 - branches.md | 53 - browser.js | 3 + browser.js.map | 1 + dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 39 - docs/types/index.d.ts | 177 - docs/types/test.ts | 45 - examples/c/Makefile | 146 - examples/c/example.c | 50 - examples/index.js | 54 - .../stdlib/ndarray/base/broadcast_shapes.h | 40 - index.js | 3 + index.js.map | 1 + lib/index.js | 45 - lib/main.js | 256 - manifest.json | 38 - package.json | 58 +- src/main.c | 118 - stats_browser.html | 6177 +++++++++++++++++ stats_node.html | 6177 +++++++++++++++++ test/dist/test.js | 230 - test/test.js | 230 - 51 files changed, 12400 insertions(+), 5303 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.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 branches.md create mode 100644 browser.js create mode 100644 browser.js.map 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/index.d.ts delete mode 100644 docs/types/test.ts delete mode 100644 examples/c/Makefile delete mode 100644 examples/c/example.c delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/broadcast_shapes.h create mode 100644 index.js create mode 100644 index.js.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 manifest.json delete mode 100644 src/main.c create mode 100644 stats_browser.html create mode 100644 stats_node.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 7f004ad..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 a07d970..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 b69deb3..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: '0 12 * * 5' - - # 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 +``` + +If no recognized module system is present, access bundle contents via the global scope: + +```html + ``` #### broadcastShapes( shapes ) @@ -243,9 +251,14 @@ var sh = broadcastShapes( [ sh1, sh2 ] ); -```javascript -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); +```html + + + + + + + + ```
@@ -286,131 +304,7 @@ for ( i = 0; i < shapes.length; i++ ) { -* * * - -
- -## C APIs - - - -
- -
- - - - - -
- -### Usage - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -``` - -#### stdlib_ndarray_broadcast_shapes( M, \*\*shapes, \*ndims, \*out ) - -Broadcasts array shapes to a single shape. - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -int64_t N1 = 4; -int64_t sh1[] = { 8, 1, 6, 1 }; - -int64_t N2 = 3; -int64_t sh2[] = { 7, 1, 5 }; - -int64_t ndims[] = { N1, N2 }; -int64_t *shapes[] = { sh1, sh2 }; - -int64_t out[] = { 0, 0, 0, 0 }; -int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -if ( status != 0 ) { - // Handle error... -} -``` - -The function accepts the following arguments: - -- **M**: `[in] int64_t` number of shape arrays. -- **shapes**: `[in] int64_t**` array of shape arrays (dimensions). -- **ndims**: `[in] int64_t*` number of dimensions for each respective shape array. -- **out**: `[out] int64_t*` output shape array. - -```c -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ); -``` - -If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). - -
- - - - - -
- -### Notes - -- Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. - -
- - - - - -
- -### Examples - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main( void ) { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} -``` - -
- - - -
- diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index fa610dc..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,112 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pkg = require( './../package.json' ).name; -var broadcastShapes = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::two_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ] ], - [ [ 3, 2 ], [ 3, 1 ] ], - [ [ 1, 1 ], [ 2, 2 ] ], - [ [ 1 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::three_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::four_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ], [ 8, 1, 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ], [ 1, 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ], [ 1, 1, 2, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ], [ 1 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ], [ 5, 1, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/c/Makefile b/benchmark/c/Makefile deleted file mode 100644 index 5dc545c..0000000 --- a/benchmark/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := benchmark.out - - -# RULES # - -#/ -# Compiles C source files. -# -# @param {string} SOURCE_FILES - list of C source files -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lpthread -lblas`) -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [C_COMPILER] - C compiler -# @param {string} [CFLAGS] - C compiler flags -# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} SOURCE_FILES - list of C source files -# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {(string|void)} LIBRARIES - list of libraries (e.g., `-lpthread -lblas`) -# @param {(string|void)} LIBPATH - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} CC - C compiler -# @param {string} CFLAGS - C compiler flags -# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled benchmarks. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/benchmark/c/benchmark.c b/benchmark/c/benchmark.c deleted file mode 100644 index be62cd5..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,152 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/** -* Benchmark `broadcast_shapes`. -*/ -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "broadcast-shapes" -#define ITERATIONS 1000000 -#define REPEATS 3 - -/** -* Prints the TAP version. -*/ -void print_version() { - printf( "TAP version 13\n" ); -} - -/** -* Prints the TAP summary. -* -* @param total total number of tests -* @param passing total number of passing tests -*/ -void print_summary( int total, int passing ) { - printf( "#\n" ); - printf( "1..%d\n", total ); // TAP plan - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); -} - -/** -* Prints benchmarks results. -* -* @param elapsed elapsed time in seconds -*/ -void print_results( double elapsed ) { - double rate = (double)ITERATIONS / elapsed; - printf( " ---\n" ); - printf( " iterations: %d\n", ITERATIONS ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", rate ); - printf( " ...\n" ); -} - -/** -* Returns a clock time. -* -* @return clock time -*/ -double tic() { - struct timeval now; - gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; -} - -/** -* Generates a random double on the interval [0,1]. -* -* @return random double -*/ -double rand_double() { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark() { - double elapsed; - int8_t status; - double t; - int i; - - int64_t sh1[] = { 8, 1, 6, 1 }; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { 4, 3 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( out[ 0 ] != 8 ) { - printf( "unexpected result\n" ); - } - if ( out[ 1 ] != 7 ) { - printf( "unexpected result\n" ); - } - if ( out[ 2 ] != 6 ) { - printf( "unexpected result\n" ); - } - if ( out[ 3 ] != 5 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Main execution sequence. -*/ -int main( void ) { - double elapsed; - int i; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - for ( i = 0; i < REPEATS; i++ ) { - printf( "# c::native::%s::two_arrays\n", NAME ); - elapsed = benchmark(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", i+1 ); - } - print_summary( REPEATS, REPEATS ); -} diff --git a/branches.md b/branches.md deleted file mode 100644 index 27a33c4..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes" -%% click B href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm \ No newline at end of file diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..3faa0cd --- /dev/null +++ b/browser.js @@ -0,0 +1,3 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map new file mode 100644 index 0000000..aa4b2bb --- /dev/null +++ b/browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"browser.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 87ea8b6..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import broadcastShapes from '../docs/types/index'; -export = broadcastShapes; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 625741a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var d=function(t,e){return function(){return e||t((e={exports:{}}).exports,e),e.exports}};var h=d(function(x,c){ -function g(t){var e,n,u,o,s,l,a,f,i,r,v;if(f=t.length,n=[],f===0)return n;if(o=t[0],i=o.length,f===1){for(r=0;ri&&(i=e[r]);for(r=0;r=0;){for(s=e[0]-i+r,s>=0?u=o[s]:u=1,v=1;v=0?a=t[v][l]:a=1,u===1){u=a;continue}if(!(a===1||u===a))return null}n[r]=u,r-=1}return n}c.exports=g -});var m=h();module.exports=m; -/** @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 db2949f..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = broadcastShapes;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast array shapes to a single shape.\n*\n* @module @stdlib/ndarray-base-broadcast-shapes\n*\n* @example\n* var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' );\n*\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\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,cAkLA,SAASC,EAAiBC,EAAS,CAClC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GAFAH,EAAIR,EAAO,OACXE,EAAM,CAAC,EACFM,IAAM,EACV,OAAON,EAMR,GAJAE,EAAKJ,EAAQ,CAAE,EACfS,EAAIL,EAAG,OAGFI,IAAM,EAAI,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAI,KAAME,EAAIM,CAAE,CAAE,EAEnB,OAAOR,CACR,CAGA,IADAD,EAAQ,CAAEQ,CAAE,EACNC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAM,KAAMD,EAAQU,CAAE,EAAE,MAAO,EAC1BT,EAAOS,CAAE,EAAID,IACjBA,EAAIR,EAAOS,CAAE,GAIf,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAI,KAAM,CAAE,EAIb,IADAQ,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IANAL,EAAKJ,EAAO,CAAE,EAAIQ,EAAIC,EACjBL,GAAM,EACVF,EAAMC,EAAIC,CAAG,EAEbF,EAAM,EAEDQ,EAAI,EAAGA,EAAIH,EAAGG,IAAM,CAOzB,GANAL,EAAKL,EAAOU,CAAE,EAAIF,EAAIC,EACjBJ,GAAM,EACVC,EAAIP,EAAQW,CAAE,EAAGL,CAAG,EAEpBC,EAAI,EAEAJ,IAAQ,EAAI,CAChBA,EAAMI,EACN,QACD,CACA,GAAK,EAAAA,IAAM,GAAKJ,IAAQI,GAKxB,OAAO,IACR,CACAL,EAAKQ,CAAE,EAAIP,EACXO,GAAK,CACN,CACA,OAAOR,CACR,CAKAJ,EAAO,QAAUC,ICxNjB,IAAIa,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "broadcastShapes", "shapes", "ndims", "out", "dim", "sh", "n1", "n2", "d", "M", "N", "i", "j", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f1d92f6..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,39 +0,0 @@ - -{{alias}}( shapes ) - Broadcasts array shapes to a single shape. - - Two respective dimensions in two shape arrays are compatible if - - 1. the dimensions are equal. - 2. one dimension is `1`. - - The function returns `null` if provided incompatible shapes (i.e., shapes - which cannot be broadcast with one another). - - Parameters - ---------- - shapes: Array - Array of shape arrays. - - Returns - ------- - out: Array|null - Broadcast shape. - - Examples - -------- - // Compatible shapes: - > var sh1 = [ 8, 1, 6, 1 ]; - > var sh2 = [ 7, 1, 5 ]; - > var sh = {{alias}}( [ sh1, sh2 ] ) - [ 8, 7, 6, 5 ] - - // Incompatible shapes: - > sh1 = [ 3, 2 ]; - > sh1 = [ 2, 3 ]; - > sh = {{alias}}( [ sh1, sh2 ] ) - null - - See Also - -------- - diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts deleted file mode 100644 index f5174e9..0000000 --- a/docs/types/index.d.ts +++ /dev/null @@ -1,177 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ArrayLike } from '@stdlib/types/array'; - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param shapes - array shapes -* @returns broadcast shape -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -declare function broadcastShapes( shapes: ArrayLike> ): ArrayLike; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = broadcastShapes; diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 2886539..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 broadcastShapes = require( './index' ); - - -// TESTS // - -// The function returns an array of numbers... -{ - broadcastShapes( [ [ 1, 2 ], [ 2, 2 ] ] ); // $ExpectType ArrayLike -} - -// The compiler throws an error if the function is not provided an array-like object containing array-like objects containing numbers... -{ - broadcastShapes( '5' ); // $ExpectError - broadcastShapes( 5 ); // $ExpectError - broadcastShapes( true ); // $ExpectError - broadcastShapes( false ); // $ExpectError - broadcastShapes( null ); // $ExpectError - broadcastShapes( {} ); // $ExpectError - broadcastShapes( [ '5' ] ); // $ExpectError - broadcastShapes( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - broadcastShapes(); // $ExpectError - broadcastShapes( [ [ 1, 2, 3 ] ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/c/Makefile b/examples/c/Makefile deleted file mode 100644 index 70c91f4..0000000 --- a/examples/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := example.out - - -# RULES # - -#/ -# Compiles source files. -# -# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) -# @param {string} [CFLAGS] - C compiler options -# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) -# @param {string} [SOURCE_FILES] - list of source files -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} CC - C compiler (e.g., `gcc`) -# @param {string} CFLAGS - C compiler options -# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) -# @param {string} SOURCE_FILES - list of source files -# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) -# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled examples. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/examples/c/example.c b/examples/c/example.c deleted file mode 100644 index 4bc54d5..0000000 --- a/examples/c/example.c +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main( void ) { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 28811f9..0000000 --- a/examples/index.js +++ /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. -*/ - -'use strict'; - -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( './../lib' ); - -var shapes; -var out; -var sh; -var i; -var j; - -function shape2string( shape ) { - return lpad( shape.join( ' x ' ), 20, ' ' ); -} - -shapes = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] -]; - -for ( i = 0; i < shapes.length; i++ ) { - sh = shapes[ i ]; - for ( j = 0; j < sh.length; j++ ) { - console.log( shape2string( sh[ j ] ) ); - } - console.log( lpad( '', 20, '-' ) ); - - out = broadcastShapes( sh ); - console.log( shape2string( out )+'\n' ); -} diff --git a/include/stdlib/ndarray/base/broadcast_shapes.h b/include/stdlib/ndarray/base/broadcast_shapes.h deleted file mode 100644 index e23dce1..0000000 --- a/include/stdlib/ndarray/base/broadcast_shapes.h +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#ifndef STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H -#define STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H - -#include - -/* -* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. -*/ -#ifdef __cplusplus -extern "C" { -#endif - -/** -* Broadcasts array shapes to a single shape. -*/ -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H diff --git a/index.js b/index.js new file mode 100644 index 0000000..c1ce4fa --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map new file mode 100644 index 0000000..0c02c0f --- /dev/null +++ b/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 0c9817e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Broadcast array shapes to a single shape. -* -* @module @stdlib/ndarray-base-broadcast-shapes -* -* @example -* var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); -* -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -*/ - -// 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 8558e60..0000000 --- a/lib/main.js +++ /dev/null @@ -1,256 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param {Array} shapes - array of shape arrays -* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`) -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [ 8, 0, 1, 6, 1 ], -* [ 8, 8, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -function broadcastShapes( shapes ) { - var ndims; - var out; - var dim; - var sh; - var n1; - var n2; - var d; - var M; - var N; - var i; - var j; - - M = shapes.length; - out = []; - if ( M === 0 ) { - return out; - } - sh = shapes[ 0 ]; - N = sh.length; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M === 1 ) { - // Need to manually copy to output shape, as shapes could be array-like objects... - for ( i = 0; i < N; i++ ) { - out.push( sh[ i ] ); - } - return out; - } - // Determine the maximum dimensionality... - ndims = [ N ]; - for ( i = 1; i < M; i++ ) { - ndims.push( shapes[ i ].length ); - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Initialize the output array... - for ( i = 0; i < N; i++ ) { - out.push( 0 ); - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim === 1 ) { - dim = d; - continue; - } - if ( d === 1 || dim === d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return null; - } - out[ i ] = dim; - i -= 1; - } - return out; -} - - -// EXPORTS // - -module.exports = broadcastShapes; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 890a937..0000000 --- a/manifest.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "options": {}, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [] - } - ] -} diff --git a/package.json b/package.json index bd62ab1..b48d2f6 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,7 @@ "version": "0.1.1", "description": "Broadcast array shapes to a single shape.", "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", - "include": "./include", - "lib": "./lib", - "src": "./src", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "main": "./index.js", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,33 +12,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/types": "^0.1.0", - "@stdlib/utils-library-manifest": "^0.1.1", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1" - }, - "devDependencies": { - "@stdlib/bench": "^0.1.0", - "@stdlib/string-left-pad": "^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", "stdtypes", @@ -80,9 +27,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 35a3654..0000000 --- a/src/main.c +++ /dev/null @@ -1,118 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). -* -* - Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. -* -* @param M number of array shapes -* @param shapes pointer to an array containing shape arrays -* @param ndims array containing the number of dimensions for (i.e., length of) each respective shape array -* @param out pointer to output array -* @return status -* -* @example -* #include "stdlib/ndarray/base/broadcast_shapes.h" -* #include -* -* int64_t N1 = 4; -* int64_t sh1[] = { 8, 1, 6, 1 }; -* -* int64_t N2 = 3; -* int64_t sh2[] = { 7, 1, 5 }; -* -* int64_t ndims[] = { N1, N2 }; -* int64_t *shapes[] = { sh1, sh2 }; -* -* int64_t out[] = { 0, 0, 0, 0 }; -* int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -*/ -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ) { - int64_t dim; - int64_t *sh; - int64_t n1; - int64_t n2; - int64_t d; - int64_t N; - int64_t i; - int64_t j; - - if ( M == 0 ) { - return 0; - } - sh = shapes[ 0 ]; - N = ndims[ 0 ]; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M == 1 ) { - for ( i = 0; i < N; i++ ) { - out[ i ] = sh[ i ]; - } - return 0; - } - // Determine the maximum dimensionality... - for ( i = 1; i < M; i++ ) { - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim == 1 ) { - dim = d; - continue; - } - if ( d == 1 || dim == d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return -1; - } - out[ i ] = dim; - i -= 1; - } - return 0; -} diff --git a/stats_browser.html b/stats_browser.html new file mode 100644 index 0000000..15c6804 --- /dev/null +++ b/stats_browser.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/stats_node.html b/stats_node.html new file mode 100644 index 0000000..b8aa46d --- /dev/null +++ b/stats_node.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index 4740dac..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,230 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var broadcastShapes = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastShapes, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] - ]; - - expected = [ - [ 1, 2 ], - [ 3, 4 ], - [ 5, 6, 7 ], - [ 3, 3 ], - [ 3 ], - [ 3, 2 ], - [ 2, 3 ], - [ 1, 2 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty dims)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 0 ], [ 0, 0 ] ], - [ [ 0, 1 ], [ 0, 0 ] ], - [ [ 1, 0 ], [ 0, 1 ] ], - [ [ 1, 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 1, 0 ] ], - [ [ 1, 1 ], [ 0, 1 ] ], - [ [ 0 ], [ 0, 0 ] ], - [ [ 0 ], [ 0, 1 ] ], - [ [ 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 0 ] ], - [ [ 1 ], [ 0, 1 ] ], - [ [ 1 ], [ 1, 0 ] ], - [ [ 1 ], [ 8, 0 ] ], - [ [ 8, 1, 6, 1 ], [ 0, 1, 5 ] ], - [ [ 8, 0, 6, 1 ], [ 1, 5 ] ] - ]; - - expected = [ - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 1, 0 ], - [ 8, 0 ], - [ 8, 0, 6, 5 ], - [ 8, 0, 6, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (no shapes)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [] - ]; - - expected = [ - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty shapes (i.e., zero-dimensional array broadcasting))', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [] ], - [ [], [] ], - [ [], [], [] ], - [ [], [ 0 ] ], - [ [ 0 ], [] ], - [ [], [ 0, 0 ] ], - [ [ 0, 0 ], [] ], - [ [], [ 1, 0 ] ], - [ [], [ 0, 1 ] ], - [ [], [ 3, 3 ] ], - [ [], [ 3, 3 ], [] ] - ]; - - expected = [ - [], - [], - [], - [ 0 ], - [ 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 3, 3 ], - [ 3, 3 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (single shape)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 7 ] ], - [ [ 1, 1 ] ], - [ [ 5, 6, 1 ] ] - ]; - - expected = [ - [ 7 ], - [ 1, 1 ], - [ 5, 6, 1 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function returns `null` if provided incompatible shapes', function test( t ) { - var actual; - var values; - var i; - - values = [ - [ [ 3 ], [ 4 ] ], - [ [ 2, 3 ], [ 2 ] ], - [ [ 3 ], [ 3 ], [ 4 ] ], - [ [ 1, 3, 4 ], [ 2, 3, 3 ] ], - [ [ 1, 2 ], [ 3, 1 ], [ 3, 2 ], [ 10, 5 ] ], - [ [ 2 ], [ 2, 3 ] ], - [ [ 2 ], [ 2 ], [ 2 ], [ 2 ], [ 3 ], [ 3 ], [ 3 ], [ 3 ] ], - [ [ 9, 0, 9 ], [ 0, 9, 0 ] ], - [ [ 9, 9, 9 ], [ 0, 9, 9 ] ], - [ [ 9, 0, 9 ], [ 9, 9, 9 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 0 ] ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.strictEqual( actual, null, 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 63f703c..0000000 --- a/test/test.js +++ /dev/null @@ -1,230 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var broadcastShapes = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastShapes, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] - ]; - - expected = [ - [ 1, 2 ], - [ 3, 4 ], - [ 5, 6, 7 ], - [ 3, 3 ], - [ 3 ], - [ 3, 2 ], - [ 2, 3 ], - [ 1, 2 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty dims)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 0 ], [ 0, 0 ] ], - [ [ 0, 1 ], [ 0, 0 ] ], - [ [ 1, 0 ], [ 0, 1 ] ], - [ [ 1, 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 1, 0 ] ], - [ [ 1, 1 ], [ 0, 1 ] ], - [ [ 0 ], [ 0, 0 ] ], - [ [ 0 ], [ 0, 1 ] ], - [ [ 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 0 ] ], - [ [ 1 ], [ 0, 1 ] ], - [ [ 1 ], [ 1, 0 ] ], - [ [ 1 ], [ 8, 0 ] ], - [ [ 8, 1, 6, 1 ], [ 0, 1, 5 ] ], - [ [ 8, 0, 6, 1 ], [ 1, 5 ] ] - ]; - - expected = [ - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 1, 0 ], - [ 8, 0 ], - [ 8, 0, 6, 5 ], - [ 8, 0, 6, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (no shapes)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [] - ]; - - expected = [ - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty shapes (i.e., zero-dimensional array broadcasting))', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [] ], - [ [], [] ], - [ [], [], [] ], - [ [], [ 0 ] ], - [ [ 0 ], [] ], - [ [], [ 0, 0 ] ], - [ [ 0, 0 ], [] ], - [ [], [ 1, 0 ] ], - [ [], [ 0, 1 ] ], - [ [], [ 3, 3 ] ], - [ [], [ 3, 3 ], [] ] - ]; - - expected = [ - [], - [], - [], - [ 0 ], - [ 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 3, 3 ], - [ 3, 3 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (single shape)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 7 ] ], - [ [ 1, 1 ] ], - [ [ 5, 6, 1 ] ] - ]; - - expected = [ - [ 7 ], - [ 1, 1 ], - [ 5, 6, 1 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function returns `null` if provided incompatible shapes', function test( t ) { - var actual; - var values; - var i; - - values = [ - [ [ 3 ], [ 4 ] ], - [ [ 2, 3 ], [ 2 ] ], - [ [ 3 ], [ 3 ], [ 4 ] ], - [ [ 1, 3, 4 ], [ 2, 3, 3 ] ], - [ [ 1, 2 ], [ 3, 1 ], [ 3, 2 ], [ 10, 5 ] ], - [ [ 2 ], [ 2, 3 ] ], - [ [ 2 ], [ 2 ], [ 2 ], [ 2 ], [ 3 ], [ 3 ], [ 3 ], [ 3 ] ], - [ [ 9, 0, 9 ], [ 0, 9, 0 ] ], - [ [ 9, 9, 9 ], [ 0, 9, 9 ] ], - [ [ 9, 0, 9 ], [ 9, 9, 9 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 0 ] ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.strictEqual( actual, null, 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); From 8eb294bea65b2c5f34346f01065d9b094019089d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Nov 2023 02:54:34 +0000 Subject: [PATCH 069/158] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index c8b85c0..affc4c2 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,8 @@ }, "dependencies": { "@stdlib/types": "^0.1.0", - "@stdlib/utils-library-manifest": "^0.1.1" + "@stdlib/utils-library-manifest": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1" }, "devDependencies": { "@stdlib/bench": "^0.1.0", @@ -84,4 +85,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From 797117519f5d63c59e48c9c7f0137be9091c5b77 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Nov 2023 21:54:27 +0000 Subject: [PATCH 070/158] Remove files --- browser.js | 3 - browser.js.map | 1 - index.js | 3 - index.js.map | 1 - stats_browser.html | 6177 -------------------------------------------- stats_node.html | 6177 -------------------------------------------- 6 files changed, 12362 deletions(-) delete mode 100644 browser.js delete mode 100644 browser.js.map delete mode 100644 index.js delete mode 100644 index.js.map delete mode 100644 stats_browser.html delete mode 100644 stats_node.html diff --git a/browser.js b/browser.js deleted file mode 100644 index 3faa0cd..0000000 --- a/browser.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); -//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map deleted file mode 100644 index aa4b2bb..0000000 --- a/browser.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"browser.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/index.js b/index.js deleted file mode 100644 index c1ce4fa..0000000 --- a/index.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); -//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map deleted file mode 100644 index 0c02c0f..0000000 --- a/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/stats_browser.html b/stats_browser.html deleted file mode 100644 index 15c6804..0000000 --- a/stats_browser.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - diff --git a/stats_node.html b/stats_node.html deleted file mode 100644 index b8aa46d..0000000 --- a/stats_node.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 7a89d30b9d33bfd5661bc1951b1fcea3134fee68 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Nov 2023 21:55:12 +0000 Subject: [PATCH 071/158] 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 | 178 +- benchmark/benchmark.js | 112 - benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 152 - branches.md | 53 - browser.js | 3 + browser.js.map | 1 + dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 39 - docs/types/index.d.ts | 177 - docs/types/test.ts | 45 - examples/c/Makefile | 146 - examples/c/example.c | 50 - examples/index.js | 54 - .../stdlib/ndarray/base/broadcast_shapes.h | 40 - index.js | 3 + index.js.map | 1 + lib/index.js | 45 - lib/main.js | 256 - manifest.json | 38 - package.json | 58 +- src/main.c | 118 - stats_browser.html | 6177 +++++++++++++++++ stats_node.html | 6177 +++++++++++++++++ test/dist/test.js | 33 - test/test.js | 230 - 52 files changed, 12400 insertions(+), 5115 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.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 branches.md create mode 100644 browser.js create mode 100644 browser.js.map 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/index.d.ts delete mode 100644 docs/types/test.ts delete mode 100644 examples/c/Makefile delete mode 100644 examples/c/example.c delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/broadcast_shapes.h create mode 100644 index.js create mode 100644 index.js.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 manifest.json delete mode 100644 src/main.c create mode 100644 stats_browser.html create mode 100644 stats_node.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 0426fbb..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-11-01T01:23:15.775Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 7f004ad..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 a07d970..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 b69deb3..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: '0 12 * * 5' - - # 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 +``` + +If no recognized module system is present, access bundle contents via the global scope: + +```html + ``` #### broadcastShapes( shapes ) @@ -243,9 +251,14 @@ var sh = broadcastShapes( [ sh1, sh2 ] ); -```javascript -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); +```html + + + + + + + + ```
@@ -286,131 +304,7 @@ for ( i = 0; i < shapes.length; i++ ) { -* * * - -
- -## C APIs - - - -
- -
- - - - - -
- -### Usage - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -``` - -#### stdlib_ndarray_broadcast_shapes( M, \*\*shapes, \*ndims, \*out ) - -Broadcasts array shapes to a single shape. - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -int64_t N1 = 4; -int64_t sh1[] = { 8, 1, 6, 1 }; - -int64_t N2 = 3; -int64_t sh2[] = { 7, 1, 5 }; - -int64_t ndims[] = { N1, N2 }; -int64_t *shapes[] = { sh1, sh2 }; - -int64_t out[] = { 0, 0, 0, 0 }; -int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -if ( status != 0 ) { - // Handle error... -} -``` - -The function accepts the following arguments: - -- **M**: `[in] int64_t` number of shape arrays. -- **shapes**: `[in] int64_t**` array of shape arrays (dimensions). -- **ndims**: `[in] int64_t*` number of dimensions for each respective shape array. -- **out**: `[out] int64_t*` output shape array. - -```c -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ); -``` - -If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). - -
- - - - - -
- -### Notes - -- Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. - -
- - - - - -
- -### Examples - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main( void ) { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} -``` - -
- - - -
- diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index fa610dc..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,112 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pkg = require( './../package.json' ).name; -var broadcastShapes = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::two_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ] ], - [ [ 3, 2 ], [ 3, 1 ] ], - [ [ 1, 1 ], [ 2, 2 ] ], - [ [ 1 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::three_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::four_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ], [ 8, 1, 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ], [ 1, 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ], [ 1, 1, 2, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ], [ 1 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ], [ 5, 1, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/c/Makefile b/benchmark/c/Makefile deleted file mode 100644 index 5dc545c..0000000 --- a/benchmark/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := benchmark.out - - -# RULES # - -#/ -# Compiles C source files. -# -# @param {string} SOURCE_FILES - list of C source files -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lpthread -lblas`) -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [C_COMPILER] - C compiler -# @param {string} [CFLAGS] - C compiler flags -# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} SOURCE_FILES - list of C source files -# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {(string|void)} LIBRARIES - list of libraries (e.g., `-lpthread -lblas`) -# @param {(string|void)} LIBPATH - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} CC - C compiler -# @param {string} CFLAGS - C compiler flags -# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled benchmarks. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/benchmark/c/benchmark.c b/benchmark/c/benchmark.c deleted file mode 100644 index be62cd5..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,152 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/** -* Benchmark `broadcast_shapes`. -*/ -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "broadcast-shapes" -#define ITERATIONS 1000000 -#define REPEATS 3 - -/** -* Prints the TAP version. -*/ -void print_version() { - printf( "TAP version 13\n" ); -} - -/** -* Prints the TAP summary. -* -* @param total total number of tests -* @param passing total number of passing tests -*/ -void print_summary( int total, int passing ) { - printf( "#\n" ); - printf( "1..%d\n", total ); // TAP plan - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); -} - -/** -* Prints benchmarks results. -* -* @param elapsed elapsed time in seconds -*/ -void print_results( double elapsed ) { - double rate = (double)ITERATIONS / elapsed; - printf( " ---\n" ); - printf( " iterations: %d\n", ITERATIONS ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", rate ); - printf( " ...\n" ); -} - -/** -* Returns a clock time. -* -* @return clock time -*/ -double tic() { - struct timeval now; - gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; -} - -/** -* Generates a random double on the interval [0,1]. -* -* @return random double -*/ -double rand_double() { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark() { - double elapsed; - int8_t status; - double t; - int i; - - int64_t sh1[] = { 8, 1, 6, 1 }; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { 4, 3 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( out[ 0 ] != 8 ) { - printf( "unexpected result\n" ); - } - if ( out[ 1 ] != 7 ) { - printf( "unexpected result\n" ); - } - if ( out[ 2 ] != 6 ) { - printf( "unexpected result\n" ); - } - if ( out[ 3 ] != 5 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Main execution sequence. -*/ -int main( void ) { - double elapsed; - int i; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - for ( i = 0; i < REPEATS; i++ ) { - printf( "# c::native::%s::two_arrays\n", NAME ); - elapsed = benchmark(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", i+1 ); - } - print_summary( REPEATS, REPEATS ); -} diff --git a/branches.md b/branches.md deleted file mode 100644 index 27a33c4..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes" -%% click B href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm \ No newline at end of file diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..3faa0cd --- /dev/null +++ b/browser.js @@ -0,0 +1,3 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map new file mode 100644 index 0000000..aa4b2bb --- /dev/null +++ b/browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"browser.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 87ea8b6..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import broadcastShapes from '../docs/types/index'; -export = broadcastShapes; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 625741a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var d=function(t,e){return function(){return e||t((e={exports:{}}).exports,e),e.exports}};var h=d(function(x,c){ -function g(t){var e,n,u,o,s,l,a,f,i,r,v;if(f=t.length,n=[],f===0)return n;if(o=t[0],i=o.length,f===1){for(r=0;ri&&(i=e[r]);for(r=0;r=0;){for(s=e[0]-i+r,s>=0?u=o[s]:u=1,v=1;v=0?a=t[v][l]:a=1,u===1){u=a;continue}if(!(a===1||u===a))return null}n[r]=u,r-=1}return n}c.exports=g -});var m=h();module.exports=m; -/** @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 db2949f..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = broadcastShapes;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast array shapes to a single shape.\n*\n* @module @stdlib/ndarray-base-broadcast-shapes\n*\n* @example\n* var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' );\n*\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\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,cAkLA,SAASC,EAAiBC,EAAS,CAClC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GAFAH,EAAIR,EAAO,OACXE,EAAM,CAAC,EACFM,IAAM,EACV,OAAON,EAMR,GAJAE,EAAKJ,EAAQ,CAAE,EACfS,EAAIL,EAAG,OAGFI,IAAM,EAAI,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAI,KAAME,EAAIM,CAAE,CAAE,EAEnB,OAAOR,CACR,CAGA,IADAD,EAAQ,CAAEQ,CAAE,EACNC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAM,KAAMD,EAAQU,CAAE,EAAE,MAAO,EAC1BT,EAAOS,CAAE,EAAID,IACjBA,EAAIR,EAAOS,CAAE,GAIf,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAI,KAAM,CAAE,EAIb,IADAQ,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IANAL,EAAKJ,EAAO,CAAE,EAAIQ,EAAIC,EACjBL,GAAM,EACVF,EAAMC,EAAIC,CAAG,EAEbF,EAAM,EAEDQ,EAAI,EAAGA,EAAIH,EAAGG,IAAM,CAOzB,GANAL,EAAKL,EAAOU,CAAE,EAAIF,EAAIC,EACjBJ,GAAM,EACVC,EAAIP,EAAQW,CAAE,EAAGL,CAAG,EAEpBC,EAAI,EAEAJ,IAAQ,EAAI,CAChBA,EAAMI,EACN,QACD,CACA,GAAK,EAAAA,IAAM,GAAKJ,IAAQI,GAKxB,OAAO,IACR,CACAL,EAAKQ,CAAE,EAAIP,EACXO,GAAK,CACN,CACA,OAAOR,CACR,CAKAJ,EAAO,QAAUC,ICxNjB,IAAIa,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "broadcastShapes", "shapes", "ndims", "out", "dim", "sh", "n1", "n2", "d", "M", "N", "i", "j", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f1d92f6..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,39 +0,0 @@ - -{{alias}}( shapes ) - Broadcasts array shapes to a single shape. - - Two respective dimensions in two shape arrays are compatible if - - 1. the dimensions are equal. - 2. one dimension is `1`. - - The function returns `null` if provided incompatible shapes (i.e., shapes - which cannot be broadcast with one another). - - Parameters - ---------- - shapes: Array - Array of shape arrays. - - Returns - ------- - out: Array|null - Broadcast shape. - - Examples - -------- - // Compatible shapes: - > var sh1 = [ 8, 1, 6, 1 ]; - > var sh2 = [ 7, 1, 5 ]; - > var sh = {{alias}}( [ sh1, sh2 ] ) - [ 8, 7, 6, 5 ] - - // Incompatible shapes: - > sh1 = [ 3, 2 ]; - > sh1 = [ 2, 3 ]; - > sh = {{alias}}( [ sh1, sh2 ] ) - null - - See Also - -------- - diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts deleted file mode 100644 index f5174e9..0000000 --- a/docs/types/index.d.ts +++ /dev/null @@ -1,177 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ArrayLike } from '@stdlib/types/array'; - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param shapes - array shapes -* @returns broadcast shape -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -declare function broadcastShapes( shapes: ArrayLike> ): ArrayLike; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = broadcastShapes; diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 2886539..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 broadcastShapes = require( './index' ); - - -// TESTS // - -// The function returns an array of numbers... -{ - broadcastShapes( [ [ 1, 2 ], [ 2, 2 ] ] ); // $ExpectType ArrayLike -} - -// The compiler throws an error if the function is not provided an array-like object containing array-like objects containing numbers... -{ - broadcastShapes( '5' ); // $ExpectError - broadcastShapes( 5 ); // $ExpectError - broadcastShapes( true ); // $ExpectError - broadcastShapes( false ); // $ExpectError - broadcastShapes( null ); // $ExpectError - broadcastShapes( {} ); // $ExpectError - broadcastShapes( [ '5' ] ); // $ExpectError - broadcastShapes( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - broadcastShapes(); // $ExpectError - broadcastShapes( [ [ 1, 2, 3 ] ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/c/Makefile b/examples/c/Makefile deleted file mode 100644 index 70c91f4..0000000 --- a/examples/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := example.out - - -# RULES # - -#/ -# Compiles source files. -# -# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) -# @param {string} [CFLAGS] - C compiler options -# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) -# @param {string} [SOURCE_FILES] - list of source files -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} CC - C compiler (e.g., `gcc`) -# @param {string} CFLAGS - C compiler options -# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) -# @param {string} SOURCE_FILES - list of source files -# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) -# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled examples. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/examples/c/example.c b/examples/c/example.c deleted file mode 100644 index 4bc54d5..0000000 --- a/examples/c/example.c +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main( void ) { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 28811f9..0000000 --- a/examples/index.js +++ /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. -*/ - -'use strict'; - -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( './../lib' ); - -var shapes; -var out; -var sh; -var i; -var j; - -function shape2string( shape ) { - return lpad( shape.join( ' x ' ), 20, ' ' ); -} - -shapes = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] -]; - -for ( i = 0; i < shapes.length; i++ ) { - sh = shapes[ i ]; - for ( j = 0; j < sh.length; j++ ) { - console.log( shape2string( sh[ j ] ) ); - } - console.log( lpad( '', 20, '-' ) ); - - out = broadcastShapes( sh ); - console.log( shape2string( out )+'\n' ); -} diff --git a/include/stdlib/ndarray/base/broadcast_shapes.h b/include/stdlib/ndarray/base/broadcast_shapes.h deleted file mode 100644 index e23dce1..0000000 --- a/include/stdlib/ndarray/base/broadcast_shapes.h +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#ifndef STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H -#define STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H - -#include - -/* -* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. -*/ -#ifdef __cplusplus -extern "C" { -#endif - -/** -* Broadcasts array shapes to a single shape. -*/ -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H diff --git a/index.js b/index.js new file mode 100644 index 0000000..c1ce4fa --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map new file mode 100644 index 0000000..0c02c0f --- /dev/null +++ b/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 0c9817e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Broadcast array shapes to a single shape. -* -* @module @stdlib/ndarray-base-broadcast-shapes -* -* @example -* var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); -* -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -*/ - -// 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 8558e60..0000000 --- a/lib/main.js +++ /dev/null @@ -1,256 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param {Array} shapes - array of shape arrays -* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`) -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [ 8, 0, 1, 6, 1 ], -* [ 8, 8, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -function broadcastShapes( shapes ) { - var ndims; - var out; - var dim; - var sh; - var n1; - var n2; - var d; - var M; - var N; - var i; - var j; - - M = shapes.length; - out = []; - if ( M === 0 ) { - return out; - } - sh = shapes[ 0 ]; - N = sh.length; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M === 1 ) { - // Need to manually copy to output shape, as shapes could be array-like objects... - for ( i = 0; i < N; i++ ) { - out.push( sh[ i ] ); - } - return out; - } - // Determine the maximum dimensionality... - ndims = [ N ]; - for ( i = 1; i < M; i++ ) { - ndims.push( shapes[ i ].length ); - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Initialize the output array... - for ( i = 0; i < N; i++ ) { - out.push( 0 ); - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim === 1 ) { - dim = d; - continue; - } - if ( d === 1 || dim === d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return null; - } - out[ i ] = dim; - i -= 1; - } - return out; -} - - -// EXPORTS // - -module.exports = broadcastShapes; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 890a937..0000000 --- a/manifest.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "options": {}, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [] - } - ] -} diff --git a/package.json b/package.json index affc4c2..b48d2f6 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,7 @@ "version": "0.1.1", "description": "Broadcast array shapes to a single shape.", "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", - "include": "./include", - "lib": "./lib", - "src": "./src", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "main": "./index.js", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,33 +12,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/types": "^0.1.0", - "@stdlib/utils-library-manifest": "^0.1.1", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1" - }, - "devDependencies": { - "@stdlib/bench": "^0.1.0", - "@stdlib/string-left-pad": "^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", "stdtypes", @@ -80,9 +27,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 35a3654..0000000 --- a/src/main.c +++ /dev/null @@ -1,118 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). -* -* - Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. -* -* @param M number of array shapes -* @param shapes pointer to an array containing shape arrays -* @param ndims array containing the number of dimensions for (i.e., length of) each respective shape array -* @param out pointer to output array -* @return status -* -* @example -* #include "stdlib/ndarray/base/broadcast_shapes.h" -* #include -* -* int64_t N1 = 4; -* int64_t sh1[] = { 8, 1, 6, 1 }; -* -* int64_t N2 = 3; -* int64_t sh2[] = { 7, 1, 5 }; -* -* int64_t ndims[] = { N1, N2 }; -* int64_t *shapes[] = { sh1, sh2 }; -* -* int64_t out[] = { 0, 0, 0, 0 }; -* int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -*/ -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ) { - int64_t dim; - int64_t *sh; - int64_t n1; - int64_t n2; - int64_t d; - int64_t N; - int64_t i; - int64_t j; - - if ( M == 0 ) { - return 0; - } - sh = shapes[ 0 ]; - N = ndims[ 0 ]; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M == 1 ) { - for ( i = 0; i < N; i++ ) { - out[ i ] = sh[ i ]; - } - return 0; - } - // Determine the maximum dimensionality... - for ( i = 1; i < M; i++ ) { - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim == 1 ) { - dim = d; - continue; - } - if ( d == 1 || dim == d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return -1; - } - out[ i ] = dim; - i -= 1; - } - return 0; -} diff --git a/stats_browser.html b/stats_browser.html new file mode 100644 index 0000000..f7fe03b --- /dev/null +++ b/stats_browser.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/stats_node.html b/stats_node.html new file mode 100644 index 0000000..4290788 --- /dev/null +++ b/stats_node.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 63f703c..0000000 --- a/test/test.js +++ /dev/null @@ -1,230 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var broadcastShapes = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastShapes, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] - ]; - - expected = [ - [ 1, 2 ], - [ 3, 4 ], - [ 5, 6, 7 ], - [ 3, 3 ], - [ 3 ], - [ 3, 2 ], - [ 2, 3 ], - [ 1, 2 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty dims)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 0 ], [ 0, 0 ] ], - [ [ 0, 1 ], [ 0, 0 ] ], - [ [ 1, 0 ], [ 0, 1 ] ], - [ [ 1, 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 1, 0 ] ], - [ [ 1, 1 ], [ 0, 1 ] ], - [ [ 0 ], [ 0, 0 ] ], - [ [ 0 ], [ 0, 1 ] ], - [ [ 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 0 ] ], - [ [ 1 ], [ 0, 1 ] ], - [ [ 1 ], [ 1, 0 ] ], - [ [ 1 ], [ 8, 0 ] ], - [ [ 8, 1, 6, 1 ], [ 0, 1, 5 ] ], - [ [ 8, 0, 6, 1 ], [ 1, 5 ] ] - ]; - - expected = [ - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 1, 0 ], - [ 8, 0 ], - [ 8, 0, 6, 5 ], - [ 8, 0, 6, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (no shapes)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [] - ]; - - expected = [ - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty shapes (i.e., zero-dimensional array broadcasting))', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [] ], - [ [], [] ], - [ [], [], [] ], - [ [], [ 0 ] ], - [ [ 0 ], [] ], - [ [], [ 0, 0 ] ], - [ [ 0, 0 ], [] ], - [ [], [ 1, 0 ] ], - [ [], [ 0, 1 ] ], - [ [], [ 3, 3 ] ], - [ [], [ 3, 3 ], [] ] - ]; - - expected = [ - [], - [], - [], - [ 0 ], - [ 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 3, 3 ], - [ 3, 3 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (single shape)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 7 ] ], - [ [ 1, 1 ] ], - [ [ 5, 6, 1 ] ] - ]; - - expected = [ - [ 7 ], - [ 1, 1 ], - [ 5, 6, 1 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function returns `null` if provided incompatible shapes', function test( t ) { - var actual; - var values; - var i; - - values = [ - [ [ 3 ], [ 4 ] ], - [ [ 2, 3 ], [ 2 ] ], - [ [ 3 ], [ 3 ], [ 4 ] ], - [ [ 1, 3, 4 ], [ 2, 3, 3 ] ], - [ [ 1, 2 ], [ 3, 1 ], [ 3, 2 ], [ 10, 5 ] ], - [ [ 2 ], [ 2, 3 ] ], - [ [ 2 ], [ 2 ], [ 2 ], [ 2 ], [ 3 ], [ 3 ], [ 3 ], [ 3 ] ], - [ [ 9, 0, 9 ], [ 0, 9, 0 ] ], - [ [ 9, 9, 9 ], [ 0, 9, 9 ] ], - [ [ 9, 0, 9 ], [ 9, 9, 9 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 0 ] ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.strictEqual( actual, null, 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); From 2bd49ab5e349300ada8d2cc012bb8b70a238d30d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Dec 2023 02:47:39 +0000 Subject: [PATCH 072/158] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index e2eb3e4..05e1e14 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,8 @@ }, "dependencies": { "@stdlib/types": "^0.2.0", - "@stdlib/utils-library-manifest": "^0.1.1" + "@stdlib/utils-library-manifest": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1" }, "devDependencies": { "@stdlib/bench": "^0.2.1", @@ -84,4 +85,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From 2c66f12319d0230cabbb4a3112b1c60f7b4b0809 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Dec 2023 14:51:07 +0000 Subject: [PATCH 073/158] Remove files --- browser.js | 3 - browser.js.map | 1 - index.js | 3 - index.js.map | 1 - stats_browser.html | 6177 -------------------------------------------- stats_node.html | 6177 -------------------------------------------- 6 files changed, 12362 deletions(-) delete mode 100644 browser.js delete mode 100644 browser.js.map delete mode 100644 index.js delete mode 100644 index.js.map delete mode 100644 stats_browser.html delete mode 100644 stats_node.html diff --git a/browser.js b/browser.js deleted file mode 100644 index 3faa0cd..0000000 --- a/browser.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); -//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map deleted file mode 100644 index aa4b2bb..0000000 --- a/browser.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"browser.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/index.js b/index.js deleted file mode 100644 index c1ce4fa..0000000 --- a/index.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); -//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map deleted file mode 100644 index 0c02c0f..0000000 --- a/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/stats_browser.html b/stats_browser.html deleted file mode 100644 index f7fe03b..0000000 --- a/stats_browser.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - diff --git a/stats_node.html b/stats_node.html deleted file mode 100644 index 4290788..0000000 --- a/stats_node.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 30795b2e05c350bfa4f68843466519821aef61b0 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Dec 2023 14:51:44 +0000 Subject: [PATCH 074/158] 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 | 178 +- benchmark/benchmark.js | 112 - benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 152 - branches.md | 53 - browser.js | 3 + browser.js.map | 1 + dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 39 - docs/types/index.d.ts | 177 - docs/types/test.ts | 45 - examples/c/Makefile | 146 - examples/c/example.c | 50 - examples/index.js | 54 - .../stdlib/ndarray/base/broadcast_shapes.h | 40 - index.js | 3 + index.js.map | 1 + lib/index.js | 45 - lib/main.js | 256 - manifest.json | 38 - package.json | 58 +- src/main.c | 118 - stats_browser.html | 6177 +++++++++++++++++ stats_node.html | 6177 +++++++++++++++++ test/dist/test.js | 33 - test/test.js | 230 - 52 files changed, 12400 insertions(+), 5110 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.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 branches.md create mode 100644 browser.js create mode 100644 browser.js.map 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/index.d.ts delete mode 100644 docs/types/test.ts delete mode 100644 examples/c/Makefile delete mode 100644 examples/c/example.c delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/broadcast_shapes.h create mode 100644 index.js create mode 100644 index.js.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 manifest.json delete mode 100644 src/main.c create mode 100644 stats_browser.html create mode 100644 stats_node.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 62080f1..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-12-01T01:27:41.732Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 7f004ad..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 a07d970..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 b69deb3..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: '0 12 * * 5' - - # 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 +``` + +If no recognized module system is present, access bundle contents via the global scope: + +```html + ``` #### broadcastShapes( shapes ) @@ -243,9 +251,14 @@ var sh = broadcastShapes( [ sh1, sh2 ] ); -```javascript -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); +```html + + + + + + + + ```
@@ -286,131 +304,7 @@ for ( i = 0; i < shapes.length; i++ ) { -* * * - -
- -## C APIs - - - -
- -
- - - - - -
- -### Usage - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -``` - -#### stdlib_ndarray_broadcast_shapes( M, \*\*shapes, \*ndims, \*out ) - -Broadcasts array shapes to a single shape. - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -int64_t N1 = 4; -int64_t sh1[] = { 8, 1, 6, 1 }; - -int64_t N2 = 3; -int64_t sh2[] = { 7, 1, 5 }; - -int64_t ndims[] = { N1, N2 }; -int64_t *shapes[] = { sh1, sh2 }; - -int64_t out[] = { 0, 0, 0, 0 }; -int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -if ( status != 0 ) { - // Handle error... -} -``` - -The function accepts the following arguments: - -- **M**: `[in] int64_t` number of shape arrays. -- **shapes**: `[in] int64_t**` array of shape arrays (dimensions). -- **ndims**: `[in] int64_t*` number of dimensions for each respective shape array. -- **out**: `[out] int64_t*` output shape array. - -```c -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ); -``` - -If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). - -
- - - - - -
- -### Notes - -- Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. - -
- - - - - -
- -### Examples - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main( void ) { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} -``` - -
- - - -
- diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index fa610dc..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,112 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pkg = require( './../package.json' ).name; -var broadcastShapes = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::two_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ] ], - [ [ 3, 2 ], [ 3, 1 ] ], - [ [ 1, 1 ], [ 2, 2 ] ], - [ [ 1 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::three_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::four_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ], [ 8, 1, 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ], [ 1, 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ], [ 1, 1, 2, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ], [ 1 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ], [ 5, 1, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/c/Makefile b/benchmark/c/Makefile deleted file mode 100644 index 5dc545c..0000000 --- a/benchmark/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := benchmark.out - - -# RULES # - -#/ -# Compiles C source files. -# -# @param {string} SOURCE_FILES - list of C source files -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lpthread -lblas`) -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [C_COMPILER] - C compiler -# @param {string} [CFLAGS] - C compiler flags -# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} SOURCE_FILES - list of C source files -# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {(string|void)} LIBRARIES - list of libraries (e.g., `-lpthread -lblas`) -# @param {(string|void)} LIBPATH - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} CC - C compiler -# @param {string} CFLAGS - C compiler flags -# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled benchmarks. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/benchmark/c/benchmark.c b/benchmark/c/benchmark.c deleted file mode 100644 index be62cd5..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,152 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/** -* Benchmark `broadcast_shapes`. -*/ -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "broadcast-shapes" -#define ITERATIONS 1000000 -#define REPEATS 3 - -/** -* Prints the TAP version. -*/ -void print_version() { - printf( "TAP version 13\n" ); -} - -/** -* Prints the TAP summary. -* -* @param total total number of tests -* @param passing total number of passing tests -*/ -void print_summary( int total, int passing ) { - printf( "#\n" ); - printf( "1..%d\n", total ); // TAP plan - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); -} - -/** -* Prints benchmarks results. -* -* @param elapsed elapsed time in seconds -*/ -void print_results( double elapsed ) { - double rate = (double)ITERATIONS / elapsed; - printf( " ---\n" ); - printf( " iterations: %d\n", ITERATIONS ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", rate ); - printf( " ...\n" ); -} - -/** -* Returns a clock time. -* -* @return clock time -*/ -double tic() { - struct timeval now; - gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; -} - -/** -* Generates a random double on the interval [0,1]. -* -* @return random double -*/ -double rand_double() { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark() { - double elapsed; - int8_t status; - double t; - int i; - - int64_t sh1[] = { 8, 1, 6, 1 }; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { 4, 3 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( out[ 0 ] != 8 ) { - printf( "unexpected result\n" ); - } - if ( out[ 1 ] != 7 ) { - printf( "unexpected result\n" ); - } - if ( out[ 2 ] != 6 ) { - printf( "unexpected result\n" ); - } - if ( out[ 3 ] != 5 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Main execution sequence. -*/ -int main( void ) { - double elapsed; - int i; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - for ( i = 0; i < REPEATS; i++ ) { - printf( "# c::native::%s::two_arrays\n", NAME ); - elapsed = benchmark(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", i+1 ); - } - print_summary( REPEATS, REPEATS ); -} diff --git a/branches.md b/branches.md deleted file mode 100644 index 27a33c4..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes" -%% click B href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm \ No newline at end of file diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..3faa0cd --- /dev/null +++ b/browser.js @@ -0,0 +1,3 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map new file mode 100644 index 0000000..aa4b2bb --- /dev/null +++ b/browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"browser.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 87ea8b6..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import broadcastShapes from '../docs/types/index'; -export = broadcastShapes; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 625741a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var d=function(t,e){return function(){return e||t((e={exports:{}}).exports,e),e.exports}};var h=d(function(x,c){ -function g(t){var e,n,u,o,s,l,a,f,i,r,v;if(f=t.length,n=[],f===0)return n;if(o=t[0],i=o.length,f===1){for(r=0;ri&&(i=e[r]);for(r=0;r=0;){for(s=e[0]-i+r,s>=0?u=o[s]:u=1,v=1;v=0?a=t[v][l]:a=1,u===1){u=a;continue}if(!(a===1||u===a))return null}n[r]=u,r-=1}return n}c.exports=g -});var m=h();module.exports=m; -/** @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 db2949f..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = broadcastShapes;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast array shapes to a single shape.\n*\n* @module @stdlib/ndarray-base-broadcast-shapes\n*\n* @example\n* var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' );\n*\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\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,cAkLA,SAASC,EAAiBC,EAAS,CAClC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GAFAH,EAAIR,EAAO,OACXE,EAAM,CAAC,EACFM,IAAM,EACV,OAAON,EAMR,GAJAE,EAAKJ,EAAQ,CAAE,EACfS,EAAIL,EAAG,OAGFI,IAAM,EAAI,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAI,KAAME,EAAIM,CAAE,CAAE,EAEnB,OAAOR,CACR,CAGA,IADAD,EAAQ,CAAEQ,CAAE,EACNC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAM,KAAMD,EAAQU,CAAE,EAAE,MAAO,EAC1BT,EAAOS,CAAE,EAAID,IACjBA,EAAIR,EAAOS,CAAE,GAIf,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAI,KAAM,CAAE,EAIb,IADAQ,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IANAL,EAAKJ,EAAO,CAAE,EAAIQ,EAAIC,EACjBL,GAAM,EACVF,EAAMC,EAAIC,CAAG,EAEbF,EAAM,EAEDQ,EAAI,EAAGA,EAAIH,EAAGG,IAAM,CAOzB,GANAL,EAAKL,EAAOU,CAAE,EAAIF,EAAIC,EACjBJ,GAAM,EACVC,EAAIP,EAAQW,CAAE,EAAGL,CAAG,EAEpBC,EAAI,EAEAJ,IAAQ,EAAI,CAChBA,EAAMI,EACN,QACD,CACA,GAAK,EAAAA,IAAM,GAAKJ,IAAQI,GAKxB,OAAO,IACR,CACAL,EAAKQ,CAAE,EAAIP,EACXO,GAAK,CACN,CACA,OAAOR,CACR,CAKAJ,EAAO,QAAUC,ICxNjB,IAAIa,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "broadcastShapes", "shapes", "ndims", "out", "dim", "sh", "n1", "n2", "d", "M", "N", "i", "j", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f1d92f6..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,39 +0,0 @@ - -{{alias}}( shapes ) - Broadcasts array shapes to a single shape. - - Two respective dimensions in two shape arrays are compatible if - - 1. the dimensions are equal. - 2. one dimension is `1`. - - The function returns `null` if provided incompatible shapes (i.e., shapes - which cannot be broadcast with one another). - - Parameters - ---------- - shapes: Array - Array of shape arrays. - - Returns - ------- - out: Array|null - Broadcast shape. - - Examples - -------- - // Compatible shapes: - > var sh1 = [ 8, 1, 6, 1 ]; - > var sh2 = [ 7, 1, 5 ]; - > var sh = {{alias}}( [ sh1, sh2 ] ) - [ 8, 7, 6, 5 ] - - // Incompatible shapes: - > sh1 = [ 3, 2 ]; - > sh1 = [ 2, 3 ]; - > sh = {{alias}}( [ sh1, sh2 ] ) - null - - See Also - -------- - diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts deleted file mode 100644 index c2702cf..0000000 --- a/docs/types/index.d.ts +++ /dev/null @@ -1,177 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ArrayLike } from '@stdlib/types/array'; - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param shapes - array shapes -* @returns broadcast shape -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -declare function broadcastShapes( shapes: ArrayLike> ): ArrayLike; - - -// EXPORTS // - -export = broadcastShapes; diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 2886539..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 broadcastShapes = require( './index' ); - - -// TESTS // - -// The function returns an array of numbers... -{ - broadcastShapes( [ [ 1, 2 ], [ 2, 2 ] ] ); // $ExpectType ArrayLike -} - -// The compiler throws an error if the function is not provided an array-like object containing array-like objects containing numbers... -{ - broadcastShapes( '5' ); // $ExpectError - broadcastShapes( 5 ); // $ExpectError - broadcastShapes( true ); // $ExpectError - broadcastShapes( false ); // $ExpectError - broadcastShapes( null ); // $ExpectError - broadcastShapes( {} ); // $ExpectError - broadcastShapes( [ '5' ] ); // $ExpectError - broadcastShapes( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - broadcastShapes(); // $ExpectError - broadcastShapes( [ [ 1, 2, 3 ] ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/c/Makefile b/examples/c/Makefile deleted file mode 100644 index 70c91f4..0000000 --- a/examples/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := example.out - - -# RULES # - -#/ -# Compiles source files. -# -# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) -# @param {string} [CFLAGS] - C compiler options -# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) -# @param {string} [SOURCE_FILES] - list of source files -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} CC - C compiler (e.g., `gcc`) -# @param {string} CFLAGS - C compiler options -# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) -# @param {string} SOURCE_FILES - list of source files -# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) -# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled examples. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/examples/c/example.c b/examples/c/example.c deleted file mode 100644 index 4bc54d5..0000000 --- a/examples/c/example.c +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main( void ) { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 28811f9..0000000 --- a/examples/index.js +++ /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. -*/ - -'use strict'; - -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( './../lib' ); - -var shapes; -var out; -var sh; -var i; -var j; - -function shape2string( shape ) { - return lpad( shape.join( ' x ' ), 20, ' ' ); -} - -shapes = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] -]; - -for ( i = 0; i < shapes.length; i++ ) { - sh = shapes[ i ]; - for ( j = 0; j < sh.length; j++ ) { - console.log( shape2string( sh[ j ] ) ); - } - console.log( lpad( '', 20, '-' ) ); - - out = broadcastShapes( sh ); - console.log( shape2string( out )+'\n' ); -} diff --git a/include/stdlib/ndarray/base/broadcast_shapes.h b/include/stdlib/ndarray/base/broadcast_shapes.h deleted file mode 100644 index e23dce1..0000000 --- a/include/stdlib/ndarray/base/broadcast_shapes.h +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#ifndef STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H -#define STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H - -#include - -/* -* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. -*/ -#ifdef __cplusplus -extern "C" { -#endif - -/** -* Broadcasts array shapes to a single shape. -*/ -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H diff --git a/index.js b/index.js new file mode 100644 index 0000000..c1ce4fa --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map new file mode 100644 index 0000000..0c02c0f --- /dev/null +++ b/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 0c9817e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Broadcast array shapes to a single shape. -* -* @module @stdlib/ndarray-base-broadcast-shapes -* -* @example -* var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); -* -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -*/ - -// 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 8558e60..0000000 --- a/lib/main.js +++ /dev/null @@ -1,256 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param {Array} shapes - array of shape arrays -* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`) -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [ 8, 0, 1, 6, 1 ], -* [ 8, 8, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -function broadcastShapes( shapes ) { - var ndims; - var out; - var dim; - var sh; - var n1; - var n2; - var d; - var M; - var N; - var i; - var j; - - M = shapes.length; - out = []; - if ( M === 0 ) { - return out; - } - sh = shapes[ 0 ]; - N = sh.length; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M === 1 ) { - // Need to manually copy to output shape, as shapes could be array-like objects... - for ( i = 0; i < N; i++ ) { - out.push( sh[ i ] ); - } - return out; - } - // Determine the maximum dimensionality... - ndims = [ N ]; - for ( i = 1; i < M; i++ ) { - ndims.push( shapes[ i ].length ); - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Initialize the output array... - for ( i = 0; i < N; i++ ) { - out.push( 0 ); - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim === 1 ) { - dim = d; - continue; - } - if ( d === 1 || dim === d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return null; - } - out[ i ] = dim; - i -= 1; - } - return out; -} - - -// EXPORTS // - -module.exports = broadcastShapes; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 890a937..0000000 --- a/manifest.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "options": {}, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [] - } - ] -} diff --git a/package.json b/package.json index 05e1e14..b48d2f6 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,7 @@ "version": "0.1.1", "description": "Broadcast array shapes to a single shape.", "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", - "include": "./include", - "lib": "./lib", - "src": "./src", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "main": "./index.js", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,33 +12,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/types": "^0.2.0", - "@stdlib/utils-library-manifest": "^0.1.1", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1" - }, - "devDependencies": { - "@stdlib/bench": "^0.2.1", - "@stdlib/string-left-pad": "^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", "stdtypes", @@ -80,9 +27,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 35a3654..0000000 --- a/src/main.c +++ /dev/null @@ -1,118 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). -* -* - Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. -* -* @param M number of array shapes -* @param shapes pointer to an array containing shape arrays -* @param ndims array containing the number of dimensions for (i.e., length of) each respective shape array -* @param out pointer to output array -* @return status -* -* @example -* #include "stdlib/ndarray/base/broadcast_shapes.h" -* #include -* -* int64_t N1 = 4; -* int64_t sh1[] = { 8, 1, 6, 1 }; -* -* int64_t N2 = 3; -* int64_t sh2[] = { 7, 1, 5 }; -* -* int64_t ndims[] = { N1, N2 }; -* int64_t *shapes[] = { sh1, sh2 }; -* -* int64_t out[] = { 0, 0, 0, 0 }; -* int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -*/ -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ) { - int64_t dim; - int64_t *sh; - int64_t n1; - int64_t n2; - int64_t d; - int64_t N; - int64_t i; - int64_t j; - - if ( M == 0 ) { - return 0; - } - sh = shapes[ 0 ]; - N = ndims[ 0 ]; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M == 1 ) { - for ( i = 0; i < N; i++ ) { - out[ i ] = sh[ i ]; - } - return 0; - } - // Determine the maximum dimensionality... - for ( i = 1; i < M; i++ ) { - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim == 1 ) { - dim = d; - continue; - } - if ( d == 1 || dim == d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return -1; - } - out[ i ] = dim; - i -= 1; - } - return 0; -} diff --git a/stats_browser.html b/stats_browser.html new file mode 100644 index 0000000..c2ec361 --- /dev/null +++ b/stats_browser.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/stats_node.html b/stats_node.html new file mode 100644 index 0000000..dd56010 --- /dev/null +++ b/stats_node.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 63f703c..0000000 --- a/test/test.js +++ /dev/null @@ -1,230 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var broadcastShapes = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastShapes, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] - ]; - - expected = [ - [ 1, 2 ], - [ 3, 4 ], - [ 5, 6, 7 ], - [ 3, 3 ], - [ 3 ], - [ 3, 2 ], - [ 2, 3 ], - [ 1, 2 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty dims)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 0 ], [ 0, 0 ] ], - [ [ 0, 1 ], [ 0, 0 ] ], - [ [ 1, 0 ], [ 0, 1 ] ], - [ [ 1, 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 1, 0 ] ], - [ [ 1, 1 ], [ 0, 1 ] ], - [ [ 0 ], [ 0, 0 ] ], - [ [ 0 ], [ 0, 1 ] ], - [ [ 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 0 ] ], - [ [ 1 ], [ 0, 1 ] ], - [ [ 1 ], [ 1, 0 ] ], - [ [ 1 ], [ 8, 0 ] ], - [ [ 8, 1, 6, 1 ], [ 0, 1, 5 ] ], - [ [ 8, 0, 6, 1 ], [ 1, 5 ] ] - ]; - - expected = [ - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 1, 0 ], - [ 8, 0 ], - [ 8, 0, 6, 5 ], - [ 8, 0, 6, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (no shapes)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [] - ]; - - expected = [ - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty shapes (i.e., zero-dimensional array broadcasting))', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [] ], - [ [], [] ], - [ [], [], [] ], - [ [], [ 0 ] ], - [ [ 0 ], [] ], - [ [], [ 0, 0 ] ], - [ [ 0, 0 ], [] ], - [ [], [ 1, 0 ] ], - [ [], [ 0, 1 ] ], - [ [], [ 3, 3 ] ], - [ [], [ 3, 3 ], [] ] - ]; - - expected = [ - [], - [], - [], - [ 0 ], - [ 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 3, 3 ], - [ 3, 3 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (single shape)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 7 ] ], - [ [ 1, 1 ] ], - [ [ 5, 6, 1 ] ] - ]; - - expected = [ - [ 7 ], - [ 1, 1 ], - [ 5, 6, 1 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function returns `null` if provided incompatible shapes', function test( t ) { - var actual; - var values; - var i; - - values = [ - [ [ 3 ], [ 4 ] ], - [ [ 2, 3 ], [ 2 ] ], - [ [ 3 ], [ 3 ], [ 4 ] ], - [ [ 1, 3, 4 ], [ 2, 3, 3 ] ], - [ [ 1, 2 ], [ 3, 1 ], [ 3, 2 ], [ 10, 5 ] ], - [ [ 2 ], [ 2, 3 ] ], - [ [ 2 ], [ 2 ], [ 2 ], [ 2 ], [ 3 ], [ 3 ], [ 3 ], [ 3 ] ], - [ [ 9, 0, 9 ], [ 0, 9, 0 ] ], - [ [ 9, 9, 9 ], [ 0, 9, 9 ] ], - [ [ 9, 0, 9 ], [ 9, 9, 9 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 0 ] ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.strictEqual( actual, null, 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); From 8a677f669c374d4889ca69fe6270f487f686793d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 02:05:47 +0000 Subject: [PATCH 075/158] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 2b22715..95c71af 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,8 @@ }, "dependencies": { "@stdlib/types": "^0.2.0", - "@stdlib/utils-library-manifest": "^0.1.1" + "@stdlib/utils-library-manifest": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1" }, "devDependencies": { "@stdlib/string-left-pad": "^0.1.1", @@ -84,4 +85,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From c9dbd327b78853290ae6628c539b1bdabea108e8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 05:37:44 +0000 Subject: [PATCH 076/158] Remove files --- browser.js | 3 - browser.js.map | 1 - index.js | 3 - index.js.map | 1 - stats_browser.html | 6177 -------------------------------------------- stats_node.html | 6177 -------------------------------------------- 6 files changed, 12362 deletions(-) delete mode 100644 browser.js delete mode 100644 browser.js.map delete mode 100644 index.js delete mode 100644 index.js.map delete mode 100644 stats_browser.html delete mode 100644 stats_node.html diff --git a/browser.js b/browser.js deleted file mode 100644 index 3faa0cd..0000000 --- a/browser.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); -//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map deleted file mode 100644 index aa4b2bb..0000000 --- a/browser.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"browser.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/index.js b/index.js deleted file mode 100644 index c1ce4fa..0000000 --- a/index.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); -//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map deleted file mode 100644 index 0c02c0f..0000000 --- a/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/stats_browser.html b/stats_browser.html deleted file mode 100644 index c2ec361..0000000 --- a/stats_browser.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - diff --git a/stats_node.html b/stats_node.html deleted file mode 100644 index dd56010..0000000 --- a/stats_node.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From c45ac272767b891fb4fddf72ddec6eb566b59e68 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 05:38:02 +0000 Subject: [PATCH 077/158] 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 | 178 +- SECURITY.md | 5 - benchmark/benchmark.js | 112 - benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 152 - branches.md | 53 - browser.js | 3 + browser.js.map | 1 + dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 39 - docs/types/index.d.ts | 177 - docs/types/test.ts | 45 - examples/c/Makefile | 146 - examples/c/example.c | 50 - examples/index.js | 54 - .../stdlib/ndarray/base/broadcast_shapes.h | 40 - index.js | 3 + index.js.map | 1 + lib/index.js | 45 - lib/main.js | 256 - manifest.json | 38 - package.json | 58 +- src/main.c | 118 - stats_browser.html | 6177 +++++++++++++++++ stats_node.html | 6177 +++++++++++++++++ test/dist/test.js | 33 - test/test.js | 230 - 53 files changed, 12400 insertions(+), 5116 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.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 branches.md create mode 100644 browser.js create mode 100644 browser.js.map 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/index.d.ts delete mode 100644 docs/types/test.ts delete mode 100644 examples/c/Makefile delete mode 100644 examples/c/example.c delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/broadcast_shapes.h create mode 100644 index.js create mode 100644 index.js.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 manifest.json delete mode 100644 src/main.c create mode 100644 stats_browser.html create mode 100644 stats_node.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 20034e2..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-01-01T01:20:25.220Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 7f004ad..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 a07d970..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 fe371b0..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: '0 12 * * 5' - - # 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 +``` + +If no recognized module system is present, access bundle contents via the global scope: + +```html + ``` #### broadcastShapes( shapes ) @@ -243,9 +251,14 @@ var sh = broadcastShapes( [ sh1, sh2 ] ); -```javascript -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); +```html + + + + + + + + ```
@@ -286,131 +304,7 @@ for ( i = 0; i < shapes.length; i++ ) { -* * * - -
- -## C APIs - - - -
- -
- - - - - -
- -### Usage - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -``` - -#### stdlib_ndarray_broadcast_shapes( M, \*\*shapes, \*ndims, \*out ) - -Broadcasts array shapes to a single shape. - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -int64_t N1 = 4; -int64_t sh1[] = { 8, 1, 6, 1 }; - -int64_t N2 = 3; -int64_t sh2[] = { 7, 1, 5 }; - -int64_t ndims[] = { N1, N2 }; -int64_t *shapes[] = { sh1, sh2 }; - -int64_t out[] = { 0, 0, 0, 0 }; -int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -if ( status != 0 ) { - // Handle error... -} -``` - -The function accepts the following arguments: - -- **M**: `[in] int64_t` number of shape arrays. -- **shapes**: `[in] int64_t**` array of shape arrays (dimensions). -- **ndims**: `[in] int64_t*` number of dimensions for each respective shape array. -- **out**: `[out] int64_t*` output shape array. - -```c -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ); -``` - -If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). - -
- - - - - -
- -### Notes - -- Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. - -
- - - - - -
- -### Examples - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main( void ) { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} -``` - -
- - - -
- 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.js b/benchmark/benchmark.js deleted file mode 100644 index 6426216..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,112 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pkg = require( './../package.json' ).name; -var broadcastShapes = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::two_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ] ], - [ [ 3, 2 ], [ 3, 1 ] ], - [ [ 1, 1 ], [ 2, 2 ] ], - [ [ 1 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::three_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::four_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ], [ 8, 1, 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ], [ 1, 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ], [ 1, 1, 2, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ], [ 1 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ], [ 5, 1, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/c/Makefile b/benchmark/c/Makefile deleted file mode 100644 index 5dc545c..0000000 --- a/benchmark/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := benchmark.out - - -# RULES # - -#/ -# Compiles C source files. -# -# @param {string} SOURCE_FILES - list of C source files -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lpthread -lblas`) -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [C_COMPILER] - C compiler -# @param {string} [CFLAGS] - C compiler flags -# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} SOURCE_FILES - list of C source files -# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {(string|void)} LIBRARIES - list of libraries (e.g., `-lpthread -lblas`) -# @param {(string|void)} LIBPATH - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} CC - C compiler -# @param {string} CFLAGS - C compiler flags -# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled benchmarks. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/benchmark/c/benchmark.c b/benchmark/c/benchmark.c deleted file mode 100644 index be62cd5..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,152 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/** -* Benchmark `broadcast_shapes`. -*/ -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "broadcast-shapes" -#define ITERATIONS 1000000 -#define REPEATS 3 - -/** -* Prints the TAP version. -*/ -void print_version() { - printf( "TAP version 13\n" ); -} - -/** -* Prints the TAP summary. -* -* @param total total number of tests -* @param passing total number of passing tests -*/ -void print_summary( int total, int passing ) { - printf( "#\n" ); - printf( "1..%d\n", total ); // TAP plan - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); -} - -/** -* Prints benchmarks results. -* -* @param elapsed elapsed time in seconds -*/ -void print_results( double elapsed ) { - double rate = (double)ITERATIONS / elapsed; - printf( " ---\n" ); - printf( " iterations: %d\n", ITERATIONS ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", rate ); - printf( " ...\n" ); -} - -/** -* Returns a clock time. -* -* @return clock time -*/ -double tic() { - struct timeval now; - gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; -} - -/** -* Generates a random double on the interval [0,1]. -* -* @return random double -*/ -double rand_double() { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark() { - double elapsed; - int8_t status; - double t; - int i; - - int64_t sh1[] = { 8, 1, 6, 1 }; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { 4, 3 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( out[ 0 ] != 8 ) { - printf( "unexpected result\n" ); - } - if ( out[ 1 ] != 7 ) { - printf( "unexpected result\n" ); - } - if ( out[ 2 ] != 6 ) { - printf( "unexpected result\n" ); - } - if ( out[ 3 ] != 5 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Main execution sequence. -*/ -int main( void ) { - double elapsed; - int i; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - for ( i = 0; i < REPEATS; i++ ) { - printf( "# c::native::%s::two_arrays\n", NAME ); - elapsed = benchmark(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", i+1 ); - } - print_summary( REPEATS, REPEATS ); -} diff --git a/branches.md b/branches.md deleted file mode 100644 index 27a33c4..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes" -%% click B href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm \ No newline at end of file diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..44a8074 --- /dev/null +++ b/browser.js @@ -0,0 +1,3 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map new file mode 100644 index 0000000..aa4b2bb --- /dev/null +++ b/browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"browser.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 87ea8b6..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import broadcastShapes from '../docs/types/index'; -export = broadcastShapes; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 625741a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var d=function(t,e){return function(){return e||t((e={exports:{}}).exports,e),e.exports}};var h=d(function(x,c){ -function g(t){var e,n,u,o,s,l,a,f,i,r,v;if(f=t.length,n=[],f===0)return n;if(o=t[0],i=o.length,f===1){for(r=0;ri&&(i=e[r]);for(r=0;r=0;){for(s=e[0]-i+r,s>=0?u=o[s]:u=1,v=1;v=0?a=t[v][l]:a=1,u===1){u=a;continue}if(!(a===1||u===a))return null}n[r]=u,r-=1}return n}c.exports=g -});var m=h();module.exports=m; -/** @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 db2949f..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = broadcastShapes;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast array shapes to a single shape.\n*\n* @module @stdlib/ndarray-base-broadcast-shapes\n*\n* @example\n* var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' );\n*\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\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,cAkLA,SAASC,EAAiBC,EAAS,CAClC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GAFAH,EAAIR,EAAO,OACXE,EAAM,CAAC,EACFM,IAAM,EACV,OAAON,EAMR,GAJAE,EAAKJ,EAAQ,CAAE,EACfS,EAAIL,EAAG,OAGFI,IAAM,EAAI,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAI,KAAME,EAAIM,CAAE,CAAE,EAEnB,OAAOR,CACR,CAGA,IADAD,EAAQ,CAAEQ,CAAE,EACNC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAM,KAAMD,EAAQU,CAAE,EAAE,MAAO,EAC1BT,EAAOS,CAAE,EAAID,IACjBA,EAAIR,EAAOS,CAAE,GAIf,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAI,KAAM,CAAE,EAIb,IADAQ,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IANAL,EAAKJ,EAAO,CAAE,EAAIQ,EAAIC,EACjBL,GAAM,EACVF,EAAMC,EAAIC,CAAG,EAEbF,EAAM,EAEDQ,EAAI,EAAGA,EAAIH,EAAGG,IAAM,CAOzB,GANAL,EAAKL,EAAOU,CAAE,EAAIF,EAAIC,EACjBJ,GAAM,EACVC,EAAIP,EAAQW,CAAE,EAAGL,CAAG,EAEpBC,EAAI,EAEAJ,IAAQ,EAAI,CAChBA,EAAMI,EACN,QACD,CACA,GAAK,EAAAA,IAAM,GAAKJ,IAAQI,GAKxB,OAAO,IACR,CACAL,EAAKQ,CAAE,EAAIP,EACXO,GAAK,CACN,CACA,OAAOR,CACR,CAKAJ,EAAO,QAAUC,ICxNjB,IAAIa,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "broadcastShapes", "shapes", "ndims", "out", "dim", "sh", "n1", "n2", "d", "M", "N", "i", "j", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f1d92f6..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,39 +0,0 @@ - -{{alias}}( shapes ) - Broadcasts array shapes to a single shape. - - Two respective dimensions in two shape arrays are compatible if - - 1. the dimensions are equal. - 2. one dimension is `1`. - - The function returns `null` if provided incompatible shapes (i.e., shapes - which cannot be broadcast with one another). - - Parameters - ---------- - shapes: Array - Array of shape arrays. - - Returns - ------- - out: Array|null - Broadcast shape. - - Examples - -------- - // Compatible shapes: - > var sh1 = [ 8, 1, 6, 1 ]; - > var sh2 = [ 7, 1, 5 ]; - > var sh = {{alias}}( [ sh1, sh2 ] ) - [ 8, 7, 6, 5 ] - - // Incompatible shapes: - > sh1 = [ 3, 2 ]; - > sh1 = [ 2, 3 ]; - > sh = {{alias}}( [ sh1, sh2 ] ) - null - - See Also - -------- - diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts deleted file mode 100644 index c2702cf..0000000 --- a/docs/types/index.d.ts +++ /dev/null @@ -1,177 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ArrayLike } from '@stdlib/types/array'; - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param shapes - array shapes -* @returns broadcast shape -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -declare function broadcastShapes( shapes: ArrayLike> ): ArrayLike; - - -// EXPORTS // - -export = broadcastShapes; diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 2886539..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 broadcastShapes = require( './index' ); - - -// TESTS // - -// The function returns an array of numbers... -{ - broadcastShapes( [ [ 1, 2 ], [ 2, 2 ] ] ); // $ExpectType ArrayLike -} - -// The compiler throws an error if the function is not provided an array-like object containing array-like objects containing numbers... -{ - broadcastShapes( '5' ); // $ExpectError - broadcastShapes( 5 ); // $ExpectError - broadcastShapes( true ); // $ExpectError - broadcastShapes( false ); // $ExpectError - broadcastShapes( null ); // $ExpectError - broadcastShapes( {} ); // $ExpectError - broadcastShapes( [ '5' ] ); // $ExpectError - broadcastShapes( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - broadcastShapes(); // $ExpectError - broadcastShapes( [ [ 1, 2, 3 ] ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/c/Makefile b/examples/c/Makefile deleted file mode 100644 index 70c91f4..0000000 --- a/examples/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := example.out - - -# RULES # - -#/ -# Compiles source files. -# -# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) -# @param {string} [CFLAGS] - C compiler options -# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) -# @param {string} [SOURCE_FILES] - list of source files -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} CC - C compiler (e.g., `gcc`) -# @param {string} CFLAGS - C compiler options -# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) -# @param {string} SOURCE_FILES - list of source files -# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) -# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled examples. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/examples/c/example.c b/examples/c/example.c deleted file mode 100644 index 4bc54d5..0000000 --- a/examples/c/example.c +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main( void ) { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 28811f9..0000000 --- a/examples/index.js +++ /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. -*/ - -'use strict'; - -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( './../lib' ); - -var shapes; -var out; -var sh; -var i; -var j; - -function shape2string( shape ) { - return lpad( shape.join( ' x ' ), 20, ' ' ); -} - -shapes = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] -]; - -for ( i = 0; i < shapes.length; i++ ) { - sh = shapes[ i ]; - for ( j = 0; j < sh.length; j++ ) { - console.log( shape2string( sh[ j ] ) ); - } - console.log( lpad( '', 20, '-' ) ); - - out = broadcastShapes( sh ); - console.log( shape2string( out )+'\n' ); -} diff --git a/include/stdlib/ndarray/base/broadcast_shapes.h b/include/stdlib/ndarray/base/broadcast_shapes.h deleted file mode 100644 index e23dce1..0000000 --- a/include/stdlib/ndarray/base/broadcast_shapes.h +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#ifndef STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H -#define STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H - -#include - -/* -* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. -*/ -#ifdef __cplusplus -extern "C" { -#endif - -/** -* Broadcasts array shapes to a single shape. -*/ -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H diff --git a/index.js b/index.js new file mode 100644 index 0000000..d225eb4 --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map new file mode 100644 index 0000000..0c02c0f --- /dev/null +++ b/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 0c9817e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Broadcast array shapes to a single shape. -* -* @module @stdlib/ndarray-base-broadcast-shapes -* -* @example -* var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); -* -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -*/ - -// 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 8558e60..0000000 --- a/lib/main.js +++ /dev/null @@ -1,256 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param {Array} shapes - array of shape arrays -* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`) -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [ 8, 0, 1, 6, 1 ], -* [ 8, 8, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -function broadcastShapes( shapes ) { - var ndims; - var out; - var dim; - var sh; - var n1; - var n2; - var d; - var M; - var N; - var i; - var j; - - M = shapes.length; - out = []; - if ( M === 0 ) { - return out; - } - sh = shapes[ 0 ]; - N = sh.length; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M === 1 ) { - // Need to manually copy to output shape, as shapes could be array-like objects... - for ( i = 0; i < N; i++ ) { - out.push( sh[ i ] ); - } - return out; - } - // Determine the maximum dimensionality... - ndims = [ N ]; - for ( i = 1; i < M; i++ ) { - ndims.push( shapes[ i ].length ); - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Initialize the output array... - for ( i = 0; i < N; i++ ) { - out.push( 0 ); - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim === 1 ) { - dim = d; - continue; - } - if ( d === 1 || dim === d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return null; - } - out[ i ] = dim; - i -= 1; - } - return out; -} - - -// EXPORTS // - -module.exports = broadcastShapes; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 890a937..0000000 --- a/manifest.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "options": {}, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [] - } - ] -} diff --git a/package.json b/package.json index 95c71af..b48d2f6 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,7 @@ "version": "0.1.1", "description": "Broadcast array shapes to a single shape.", "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", - "include": "./include", - "lib": "./lib", - "src": "./src", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "main": "./index.js", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,33 +12,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/types": "^0.2.0", - "@stdlib/utils-library-manifest": "^0.1.1", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1" - }, - "devDependencies": { - "@stdlib/string-left-pad": "^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", "stdtypes", @@ -80,9 +27,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 35a3654..0000000 --- a/src/main.c +++ /dev/null @@ -1,118 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). -* -* - Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. -* -* @param M number of array shapes -* @param shapes pointer to an array containing shape arrays -* @param ndims array containing the number of dimensions for (i.e., length of) each respective shape array -* @param out pointer to output array -* @return status -* -* @example -* #include "stdlib/ndarray/base/broadcast_shapes.h" -* #include -* -* int64_t N1 = 4; -* int64_t sh1[] = { 8, 1, 6, 1 }; -* -* int64_t N2 = 3; -* int64_t sh2[] = { 7, 1, 5 }; -* -* int64_t ndims[] = { N1, N2 }; -* int64_t *shapes[] = { sh1, sh2 }; -* -* int64_t out[] = { 0, 0, 0, 0 }; -* int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -*/ -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ) { - int64_t dim; - int64_t *sh; - int64_t n1; - int64_t n2; - int64_t d; - int64_t N; - int64_t i; - int64_t j; - - if ( M == 0 ) { - return 0; - } - sh = shapes[ 0 ]; - N = ndims[ 0 ]; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M == 1 ) { - for ( i = 0; i < N; i++ ) { - out[ i ] = sh[ i ]; - } - return 0; - } - // Determine the maximum dimensionality... - for ( i = 1; i < M; i++ ) { - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim == 1 ) { - dim = d; - continue; - } - if ( d == 1 || dim == d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return -1; - } - out[ i ] = dim; - i -= 1; - } - return 0; -} diff --git a/stats_browser.html b/stats_browser.html new file mode 100644 index 0000000..af612b3 --- /dev/null +++ b/stats_browser.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/stats_node.html b/stats_node.html new file mode 100644 index 0000000..721f56f --- /dev/null +++ b/stats_node.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 63f703c..0000000 --- a/test/test.js +++ /dev/null @@ -1,230 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var broadcastShapes = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastShapes, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] - ]; - - expected = [ - [ 1, 2 ], - [ 3, 4 ], - [ 5, 6, 7 ], - [ 3, 3 ], - [ 3 ], - [ 3, 2 ], - [ 2, 3 ], - [ 1, 2 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty dims)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 0 ], [ 0, 0 ] ], - [ [ 0, 1 ], [ 0, 0 ] ], - [ [ 1, 0 ], [ 0, 1 ] ], - [ [ 1, 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 1, 0 ] ], - [ [ 1, 1 ], [ 0, 1 ] ], - [ [ 0 ], [ 0, 0 ] ], - [ [ 0 ], [ 0, 1 ] ], - [ [ 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 0 ] ], - [ [ 1 ], [ 0, 1 ] ], - [ [ 1 ], [ 1, 0 ] ], - [ [ 1 ], [ 8, 0 ] ], - [ [ 8, 1, 6, 1 ], [ 0, 1, 5 ] ], - [ [ 8, 0, 6, 1 ], [ 1, 5 ] ] - ]; - - expected = [ - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 1, 0 ], - [ 8, 0 ], - [ 8, 0, 6, 5 ], - [ 8, 0, 6, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (no shapes)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [] - ]; - - expected = [ - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty shapes (i.e., zero-dimensional array broadcasting))', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [] ], - [ [], [] ], - [ [], [], [] ], - [ [], [ 0 ] ], - [ [ 0 ], [] ], - [ [], [ 0, 0 ] ], - [ [ 0, 0 ], [] ], - [ [], [ 1, 0 ] ], - [ [], [ 0, 1 ] ], - [ [], [ 3, 3 ] ], - [ [], [ 3, 3 ], [] ] - ]; - - expected = [ - [], - [], - [], - [ 0 ], - [ 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 3, 3 ], - [ 3, 3 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (single shape)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 7 ] ], - [ [ 1, 1 ] ], - [ [ 5, 6, 1 ] ] - ]; - - expected = [ - [ 7 ], - [ 1, 1 ], - [ 5, 6, 1 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function returns `null` if provided incompatible shapes', function test( t ) { - var actual; - var values; - var i; - - values = [ - [ [ 3 ], [ 4 ] ], - [ [ 2, 3 ], [ 2 ] ], - [ [ 3 ], [ 3 ], [ 4 ] ], - [ [ 1, 3, 4 ], [ 2, 3, 3 ] ], - [ [ 1, 2 ], [ 3, 1 ], [ 3, 2 ], [ 10, 5 ] ], - [ [ 2 ], [ 2, 3 ] ], - [ [ 2 ], [ 2 ], [ 2 ], [ 2 ], [ 3 ], [ 3 ], [ 3 ], [ 3 ] ], - [ [ 9, 0, 9 ], [ 0, 9, 0 ] ], - [ [ 9, 9, 9 ], [ 0, 9, 9 ] ], - [ [ 9, 0, 9 ], [ 9, 9, 9 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 0 ] ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.strictEqual( actual, null, 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); From 41eff1703c19bdc048bb04605a3008a61c548541 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Feb 2024 02:08:12 +0000 Subject: [PATCH 078/158] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 2b22715..95c71af 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,8 @@ }, "dependencies": { "@stdlib/types": "^0.2.0", - "@stdlib/utils-library-manifest": "^0.1.1" + "@stdlib/utils-library-manifest": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1" }, "devDependencies": { "@stdlib/string-left-pad": "^0.1.1", @@ -84,4 +85,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From 5333538423d7a550de3873642f548ef2f817676b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Feb 2024 04:38:52 +0000 Subject: [PATCH 079/158] Remove files --- browser.js | 3 - browser.js.map | 1 - index.js | 3 - index.js.map | 1 - stats_browser.html | 6177 -------------------------------------------- stats_node.html | 6177 -------------------------------------------- 6 files changed, 12362 deletions(-) delete mode 100644 browser.js delete mode 100644 browser.js.map delete mode 100644 index.js delete mode 100644 index.js.map delete mode 100644 stats_browser.html delete mode 100644 stats_node.html diff --git a/browser.js b/browser.js deleted file mode 100644 index 44a8074..0000000 --- a/browser.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); -//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map deleted file mode 100644 index aa4b2bb..0000000 --- a/browser.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"browser.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/index.js b/index.js deleted file mode 100644 index d225eb4..0000000 --- a/index.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); -//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map deleted file mode 100644 index 0c02c0f..0000000 --- a/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/stats_browser.html b/stats_browser.html deleted file mode 100644 index af612b3..0000000 --- a/stats_browser.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - diff --git a/stats_node.html b/stats_node.html deleted file mode 100644 index 721f56f..0000000 --- a/stats_node.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 4ff769a238033b30224af9410af2897ff988ec6c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Feb 2024 04:39:10 +0000 Subject: [PATCH 080/158] 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 | 178 +- SECURITY.md | 5 - benchmark/benchmark.js | 112 - benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 152 - branches.md | 56 - browser.js | 3 + browser.js.map | 1 + dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 39 - docs/types/index.d.ts | 177 - docs/types/test.ts | 45 - examples/c/Makefile | 146 - examples/c/example.c | 50 - examples/index.js | 54 - .../stdlib/ndarray/base/broadcast_shapes.h | 40 - index.js | 3 + index.js.map | 1 + lib/index.js | 45 - lib/main.js | 256 - manifest.json | 38 - package.json | 58 +- src/main.c | 118 - stats_browser.html | 6177 +++++++++++++++++ stats_node.html | 6177 +++++++++++++++++ test/dist/test.js | 33 - test/test.js | 230 - 53 files changed, 12399 insertions(+), 5120 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.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 branches.md create mode 100644 browser.js create mode 100644 browser.js.map 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/index.d.ts delete mode 100644 docs/types/test.ts delete mode 100644 examples/c/Makefile delete mode 100644 examples/c/example.c delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/broadcast_shapes.h create mode 100644 index.js create mode 100644 index.js.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 manifest.json delete mode 100644 src/main.c create mode 100644 stats_browser.html create mode 100644 stats_node.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 05d99a9..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-02-01T01:28:37.458Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 7f004ad..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 a07d970..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 fe371b0..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: '0 12 * * 5' - - # 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 +``` -```javascript -var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); +If no recognized module system is present, access bundle contents via the global scope: + +```html + ``` #### broadcastShapes( shapes ) @@ -245,9 +251,14 @@ var sh = broadcastShapes( [ sh1, sh2 ] ); -```javascript -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); +```html + + + + + + + + ```
@@ -288,131 +304,7 @@ for ( i = 0; i < shapes.length; i++ ) { -* * * - -
- -## C APIs - - - -
- -
- - - - - -
- -### Usage - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -``` - -#### stdlib_ndarray_broadcast_shapes( M, \*\*shapes, \*ndims, \*out ) - -Broadcasts array shapes to a single shape. - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -int64_t N1 = 4; -int64_t sh1[] = { 8, 1, 6, 1 }; - -int64_t N2 = 3; -int64_t sh2[] = { 7, 1, 5 }; - -int64_t ndims[] = { N1, N2 }; -int64_t *shapes[] = { sh1, sh2 }; - -int64_t out[] = { 0, 0, 0, 0 }; -int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -if ( status != 0 ) { - // Handle error... -} -``` - -The function accepts the following arguments: - -- **M**: `[in] int64_t` number of shape arrays. -- **shapes**: `[in] int64_t**` array of shape arrays (dimensions). -- **ndims**: `[in] int64_t*` number of dimensions for each respective shape array. -- **out**: `[out] int64_t*` output shape array. - -```c -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ); -``` - -If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). - -
- - - - - -
- -### Notes - -- Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. - -
- - - - - -
- -### Examples - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main( void ) { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} -``` - -
- - - -
- 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.js b/benchmark/benchmark.js deleted file mode 100644 index 6426216..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,112 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pkg = require( './../package.json' ).name; -var broadcastShapes = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::two_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ] ], - [ [ 3, 2 ], [ 3, 1 ] ], - [ [ 1, 1 ], [ 2, 2 ] ], - [ [ 1 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::three_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::four_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ], [ 8, 1, 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ], [ 1, 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ], [ 1, 1, 2, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ], [ 1 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ], [ 5, 1, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/c/Makefile b/benchmark/c/Makefile deleted file mode 100644 index 5dc545c..0000000 --- a/benchmark/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := benchmark.out - - -# RULES # - -#/ -# Compiles C source files. -# -# @param {string} SOURCE_FILES - list of C source files -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lpthread -lblas`) -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [C_COMPILER] - C compiler -# @param {string} [CFLAGS] - C compiler flags -# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} SOURCE_FILES - list of C source files -# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {(string|void)} LIBRARIES - list of libraries (e.g., `-lpthread -lblas`) -# @param {(string|void)} LIBPATH - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} CC - C compiler -# @param {string} CFLAGS - C compiler flags -# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled benchmarks. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/benchmark/c/benchmark.c b/benchmark/c/benchmark.c deleted file mode 100644 index be62cd5..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,152 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/** -* Benchmark `broadcast_shapes`. -*/ -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "broadcast-shapes" -#define ITERATIONS 1000000 -#define REPEATS 3 - -/** -* Prints the TAP version. -*/ -void print_version() { - printf( "TAP version 13\n" ); -} - -/** -* Prints the TAP summary. -* -* @param total total number of tests -* @param passing total number of passing tests -*/ -void print_summary( int total, int passing ) { - printf( "#\n" ); - printf( "1..%d\n", total ); // TAP plan - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); -} - -/** -* Prints benchmarks results. -* -* @param elapsed elapsed time in seconds -*/ -void print_results( double elapsed ) { - double rate = (double)ITERATIONS / elapsed; - printf( " ---\n" ); - printf( " iterations: %d\n", ITERATIONS ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", rate ); - printf( " ...\n" ); -} - -/** -* Returns a clock time. -* -* @return clock time -*/ -double tic() { - struct timeval now; - gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; -} - -/** -* Generates a random double on the interval [0,1]. -* -* @return random double -*/ -double rand_double() { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark() { - double elapsed; - int8_t status; - double t; - int i; - - int64_t sh1[] = { 8, 1, 6, 1 }; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { 4, 3 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( out[ 0 ] != 8 ) { - printf( "unexpected result\n" ); - } - if ( out[ 1 ] != 7 ) { - printf( "unexpected result\n" ); - } - if ( out[ 2 ] != 6 ) { - printf( "unexpected result\n" ); - } - if ( out[ 3 ] != 5 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Main execution sequence. -*/ -int main( void ) { - double elapsed; - int i; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - for ( i = 0; i < REPEATS; i++ ) { - printf( "# c::native::%s::two_arrays\n", NAME ); - elapsed = benchmark(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", i+1 ); - } - print_summary( REPEATS, REPEATS ); -} diff --git a/branches.md b/branches.md deleted file mode 100644 index 79909c9..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes" -%% click B href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/blob/esm/README.md \ No newline at end of file diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..44a8074 --- /dev/null +++ b/browser.js @@ -0,0 +1,3 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map new file mode 100644 index 0000000..aa4b2bb --- /dev/null +++ b/browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"browser.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 87ea8b6..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import broadcastShapes from '../docs/types/index'; -export = broadcastShapes; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 625741a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var d=function(t,e){return function(){return e||t((e={exports:{}}).exports,e),e.exports}};var h=d(function(x,c){ -function g(t){var e,n,u,o,s,l,a,f,i,r,v;if(f=t.length,n=[],f===0)return n;if(o=t[0],i=o.length,f===1){for(r=0;ri&&(i=e[r]);for(r=0;r=0;){for(s=e[0]-i+r,s>=0?u=o[s]:u=1,v=1;v=0?a=t[v][l]:a=1,u===1){u=a;continue}if(!(a===1||u===a))return null}n[r]=u,r-=1}return n}c.exports=g -});var m=h();module.exports=m; -/** @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 db2949f..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = broadcastShapes;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast array shapes to a single shape.\n*\n* @module @stdlib/ndarray-base-broadcast-shapes\n*\n* @example\n* var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' );\n*\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\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,cAkLA,SAASC,EAAiBC,EAAS,CAClC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GAFAH,EAAIR,EAAO,OACXE,EAAM,CAAC,EACFM,IAAM,EACV,OAAON,EAMR,GAJAE,EAAKJ,EAAQ,CAAE,EACfS,EAAIL,EAAG,OAGFI,IAAM,EAAI,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAI,KAAME,EAAIM,CAAE,CAAE,EAEnB,OAAOR,CACR,CAGA,IADAD,EAAQ,CAAEQ,CAAE,EACNC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAM,KAAMD,EAAQU,CAAE,EAAE,MAAO,EAC1BT,EAAOS,CAAE,EAAID,IACjBA,EAAIR,EAAOS,CAAE,GAIf,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAI,KAAM,CAAE,EAIb,IADAQ,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IANAL,EAAKJ,EAAO,CAAE,EAAIQ,EAAIC,EACjBL,GAAM,EACVF,EAAMC,EAAIC,CAAG,EAEbF,EAAM,EAEDQ,EAAI,EAAGA,EAAIH,EAAGG,IAAM,CAOzB,GANAL,EAAKL,EAAOU,CAAE,EAAIF,EAAIC,EACjBJ,GAAM,EACVC,EAAIP,EAAQW,CAAE,EAAGL,CAAG,EAEpBC,EAAI,EAEAJ,IAAQ,EAAI,CAChBA,EAAMI,EACN,QACD,CACA,GAAK,EAAAA,IAAM,GAAKJ,IAAQI,GAKxB,OAAO,IACR,CACAL,EAAKQ,CAAE,EAAIP,EACXO,GAAK,CACN,CACA,OAAOR,CACR,CAKAJ,EAAO,QAAUC,ICxNjB,IAAIa,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "broadcastShapes", "shapes", "ndims", "out", "dim", "sh", "n1", "n2", "d", "M", "N", "i", "j", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f1d92f6..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,39 +0,0 @@ - -{{alias}}( shapes ) - Broadcasts array shapes to a single shape. - - Two respective dimensions in two shape arrays are compatible if - - 1. the dimensions are equal. - 2. one dimension is `1`. - - The function returns `null` if provided incompatible shapes (i.e., shapes - which cannot be broadcast with one another). - - Parameters - ---------- - shapes: Array - Array of shape arrays. - - Returns - ------- - out: Array|null - Broadcast shape. - - Examples - -------- - // Compatible shapes: - > var sh1 = [ 8, 1, 6, 1 ]; - > var sh2 = [ 7, 1, 5 ]; - > var sh = {{alias}}( [ sh1, sh2 ] ) - [ 8, 7, 6, 5 ] - - // Incompatible shapes: - > sh1 = [ 3, 2 ]; - > sh1 = [ 2, 3 ]; - > sh = {{alias}}( [ sh1, sh2 ] ) - null - - See Also - -------- - diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts deleted file mode 100644 index c2702cf..0000000 --- a/docs/types/index.d.ts +++ /dev/null @@ -1,177 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ArrayLike } from '@stdlib/types/array'; - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param shapes - array shapes -* @returns broadcast shape -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -declare function broadcastShapes( shapes: ArrayLike> ): ArrayLike; - - -// EXPORTS // - -export = broadcastShapes; diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 2886539..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 broadcastShapes = require( './index' ); - - -// TESTS // - -// The function returns an array of numbers... -{ - broadcastShapes( [ [ 1, 2 ], [ 2, 2 ] ] ); // $ExpectType ArrayLike -} - -// The compiler throws an error if the function is not provided an array-like object containing array-like objects containing numbers... -{ - broadcastShapes( '5' ); // $ExpectError - broadcastShapes( 5 ); // $ExpectError - broadcastShapes( true ); // $ExpectError - broadcastShapes( false ); // $ExpectError - broadcastShapes( null ); // $ExpectError - broadcastShapes( {} ); // $ExpectError - broadcastShapes( [ '5' ] ); // $ExpectError - broadcastShapes( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - broadcastShapes(); // $ExpectError - broadcastShapes( [ [ 1, 2, 3 ] ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/c/Makefile b/examples/c/Makefile deleted file mode 100644 index 70c91f4..0000000 --- a/examples/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := example.out - - -# RULES # - -#/ -# Compiles source files. -# -# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) -# @param {string} [CFLAGS] - C compiler options -# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) -# @param {string} [SOURCE_FILES] - list of source files -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} CC - C compiler (e.g., `gcc`) -# @param {string} CFLAGS - C compiler options -# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) -# @param {string} SOURCE_FILES - list of source files -# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) -# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled examples. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/examples/c/example.c b/examples/c/example.c deleted file mode 100644 index 4bc54d5..0000000 --- a/examples/c/example.c +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main( void ) { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 28811f9..0000000 --- a/examples/index.js +++ /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. -*/ - -'use strict'; - -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( './../lib' ); - -var shapes; -var out; -var sh; -var i; -var j; - -function shape2string( shape ) { - return lpad( shape.join( ' x ' ), 20, ' ' ); -} - -shapes = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] -]; - -for ( i = 0; i < shapes.length; i++ ) { - sh = shapes[ i ]; - for ( j = 0; j < sh.length; j++ ) { - console.log( shape2string( sh[ j ] ) ); - } - console.log( lpad( '', 20, '-' ) ); - - out = broadcastShapes( sh ); - console.log( shape2string( out )+'\n' ); -} diff --git a/include/stdlib/ndarray/base/broadcast_shapes.h b/include/stdlib/ndarray/base/broadcast_shapes.h deleted file mode 100644 index e23dce1..0000000 --- a/include/stdlib/ndarray/base/broadcast_shapes.h +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#ifndef STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H -#define STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H - -#include - -/* -* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. -*/ -#ifdef __cplusplus -extern "C" { -#endif - -/** -* Broadcasts array shapes to a single shape. -*/ -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H diff --git a/index.js b/index.js new file mode 100644 index 0000000..d225eb4 --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map new file mode 100644 index 0000000..0c02c0f --- /dev/null +++ b/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 0c9817e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Broadcast array shapes to a single shape. -* -* @module @stdlib/ndarray-base-broadcast-shapes -* -* @example -* var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); -* -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -*/ - -// 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 8558e60..0000000 --- a/lib/main.js +++ /dev/null @@ -1,256 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param {Array} shapes - array of shape arrays -* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`) -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [ 8, 0, 1, 6, 1 ], -* [ 8, 8, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -function broadcastShapes( shapes ) { - var ndims; - var out; - var dim; - var sh; - var n1; - var n2; - var d; - var M; - var N; - var i; - var j; - - M = shapes.length; - out = []; - if ( M === 0 ) { - return out; - } - sh = shapes[ 0 ]; - N = sh.length; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M === 1 ) { - // Need to manually copy to output shape, as shapes could be array-like objects... - for ( i = 0; i < N; i++ ) { - out.push( sh[ i ] ); - } - return out; - } - // Determine the maximum dimensionality... - ndims = [ N ]; - for ( i = 1; i < M; i++ ) { - ndims.push( shapes[ i ].length ); - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Initialize the output array... - for ( i = 0; i < N; i++ ) { - out.push( 0 ); - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim === 1 ) { - dim = d; - continue; - } - if ( d === 1 || dim === d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return null; - } - out[ i ] = dim; - i -= 1; - } - return out; -} - - -// EXPORTS // - -module.exports = broadcastShapes; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 890a937..0000000 --- a/manifest.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "options": {}, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [] - } - ] -} diff --git a/package.json b/package.json index 95c71af..b48d2f6 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,7 @@ "version": "0.1.1", "description": "Broadcast array shapes to a single shape.", "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", - "include": "./include", - "lib": "./lib", - "src": "./src", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "main": "./index.js", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,33 +12,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/types": "^0.2.0", - "@stdlib/utils-library-manifest": "^0.1.1", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1" - }, - "devDependencies": { - "@stdlib/string-left-pad": "^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", "stdtypes", @@ -80,9 +27,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 35a3654..0000000 --- a/src/main.c +++ /dev/null @@ -1,118 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). -* -* - Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. -* -* @param M number of array shapes -* @param shapes pointer to an array containing shape arrays -* @param ndims array containing the number of dimensions for (i.e., length of) each respective shape array -* @param out pointer to output array -* @return status -* -* @example -* #include "stdlib/ndarray/base/broadcast_shapes.h" -* #include -* -* int64_t N1 = 4; -* int64_t sh1[] = { 8, 1, 6, 1 }; -* -* int64_t N2 = 3; -* int64_t sh2[] = { 7, 1, 5 }; -* -* int64_t ndims[] = { N1, N2 }; -* int64_t *shapes[] = { sh1, sh2 }; -* -* int64_t out[] = { 0, 0, 0, 0 }; -* int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -*/ -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ) { - int64_t dim; - int64_t *sh; - int64_t n1; - int64_t n2; - int64_t d; - int64_t N; - int64_t i; - int64_t j; - - if ( M == 0 ) { - return 0; - } - sh = shapes[ 0 ]; - N = ndims[ 0 ]; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M == 1 ) { - for ( i = 0; i < N; i++ ) { - out[ i ] = sh[ i ]; - } - return 0; - } - // Determine the maximum dimensionality... - for ( i = 1; i < M; i++ ) { - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim == 1 ) { - dim = d; - continue; - } - if ( d == 1 || dim == d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return -1; - } - out[ i ] = dim; - i -= 1; - } - return 0; -} diff --git a/stats_browser.html b/stats_browser.html new file mode 100644 index 0000000..57b3d95 --- /dev/null +++ b/stats_browser.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/stats_node.html b/stats_node.html new file mode 100644 index 0000000..a86ed99 --- /dev/null +++ b/stats_node.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 63f703c..0000000 --- a/test/test.js +++ /dev/null @@ -1,230 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var broadcastShapes = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastShapes, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] - ]; - - expected = [ - [ 1, 2 ], - [ 3, 4 ], - [ 5, 6, 7 ], - [ 3, 3 ], - [ 3 ], - [ 3, 2 ], - [ 2, 3 ], - [ 1, 2 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty dims)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 0 ], [ 0, 0 ] ], - [ [ 0, 1 ], [ 0, 0 ] ], - [ [ 1, 0 ], [ 0, 1 ] ], - [ [ 1, 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 1, 0 ] ], - [ [ 1, 1 ], [ 0, 1 ] ], - [ [ 0 ], [ 0, 0 ] ], - [ [ 0 ], [ 0, 1 ] ], - [ [ 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 0 ] ], - [ [ 1 ], [ 0, 1 ] ], - [ [ 1 ], [ 1, 0 ] ], - [ [ 1 ], [ 8, 0 ] ], - [ [ 8, 1, 6, 1 ], [ 0, 1, 5 ] ], - [ [ 8, 0, 6, 1 ], [ 1, 5 ] ] - ]; - - expected = [ - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 1, 0 ], - [ 8, 0 ], - [ 8, 0, 6, 5 ], - [ 8, 0, 6, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (no shapes)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [] - ]; - - expected = [ - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty shapes (i.e., zero-dimensional array broadcasting))', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [] ], - [ [], [] ], - [ [], [], [] ], - [ [], [ 0 ] ], - [ [ 0 ], [] ], - [ [], [ 0, 0 ] ], - [ [ 0, 0 ], [] ], - [ [], [ 1, 0 ] ], - [ [], [ 0, 1 ] ], - [ [], [ 3, 3 ] ], - [ [], [ 3, 3 ], [] ] - ]; - - expected = [ - [], - [], - [], - [ 0 ], - [ 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 3, 3 ], - [ 3, 3 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (single shape)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 7 ] ], - [ [ 1, 1 ] ], - [ [ 5, 6, 1 ] ] - ]; - - expected = [ - [ 7 ], - [ 1, 1 ], - [ 5, 6, 1 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function returns `null` if provided incompatible shapes', function test( t ) { - var actual; - var values; - var i; - - values = [ - [ [ 3 ], [ 4 ] ], - [ [ 2, 3 ], [ 2 ] ], - [ [ 3 ], [ 3 ], [ 4 ] ], - [ [ 1, 3, 4 ], [ 2, 3, 3 ] ], - [ [ 1, 2 ], [ 3, 1 ], [ 3, 2 ], [ 10, 5 ] ], - [ [ 2 ], [ 2, 3 ] ], - [ [ 2 ], [ 2 ], [ 2 ], [ 2 ], [ 3 ], [ 3 ], [ 3 ], [ 3 ] ], - [ [ 9, 0, 9 ], [ 0, 9, 0 ] ], - [ [ 9, 9, 9 ], [ 0, 9, 9 ] ], - [ [ 9, 0, 9 ], [ 9, 9, 9 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 0 ] ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.strictEqual( actual, null, 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); From b29fb34587e534accfed68f0984c1dea2d7a1953 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 14 Feb 2024 05:09:18 +0000 Subject: [PATCH 081/158] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 344a639..c8b4d11 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,8 @@ }, "dependencies": { "@stdlib/types": "^0.3.1", - "@stdlib/utils-library-manifest": "^0.2.0" + "@stdlib/utils-library-manifest": "^0.2.0", + "@stdlib/error-tools-fmtprodmsg": "^0.2.0" }, "devDependencies": { "@stdlib/string-left-pad": "^0.1.1", @@ -84,4 +85,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From fbd2551b514a9e272eb0ac48d91ef44446ff2f24 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 14 Feb 2024 07:37:08 +0000 Subject: [PATCH 082/158] Remove files --- browser.js | 3 - browser.js.map | 1 - index.js | 3 - index.js.map | 1 - stats_browser.html | 6177 -------------------------------------------- stats_node.html | 6177 -------------------------------------------- 6 files changed, 12362 deletions(-) delete mode 100644 browser.js delete mode 100644 browser.js.map delete mode 100644 index.js delete mode 100644 index.js.map delete mode 100644 stats_browser.html delete mode 100644 stats_node.html diff --git a/browser.js b/browser.js deleted file mode 100644 index 44a8074..0000000 --- a/browser.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); -//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map deleted file mode 100644 index aa4b2bb..0000000 --- a/browser.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"browser.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/index.js b/index.js deleted file mode 100644 index d225eb4..0000000 --- a/index.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); -//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map deleted file mode 100644 index 0c02c0f..0000000 --- a/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/stats_browser.html b/stats_browser.html deleted file mode 100644 index 57b3d95..0000000 --- a/stats_browser.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - diff --git a/stats_node.html b/stats_node.html deleted file mode 100644 index a86ed99..0000000 --- a/stats_node.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From f68f6d94525c13d0bfcae3c3b6ca6f43c0ca89ad Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 14 Feb 2024 07:37:27 +0000 Subject: [PATCH 083/158] 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 | 178 +- SECURITY.md | 5 - benchmark/benchmark.js | 112 - benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 152 - branches.md | 56 - browser.js | 3 + browser.js.map | 1 + dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 39 - docs/types/index.d.ts | 177 - docs/types/test.ts | 45 - examples/c/Makefile | 146 - examples/c/example.c | 50 - examples/index.js | 54 - .../stdlib/ndarray/base/broadcast_shapes.h | 40 - index.js | 3 + index.js.map | 1 + lib/index.js | 45 - lib/main.js | 256 - manifest.json | 38 - package.json | 58 +- src/main.c | 118 - stats_browser.html | 6177 +++++++++++++++++ stats_node.html | 6177 +++++++++++++++++ test/dist/test.js | 33 - test/test.js | 230 - 52 files changed, 12399 insertions(+), 5123 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.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 branches.md create mode 100644 browser.js create mode 100644 browser.js.map 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/index.d.ts delete mode 100644 docs/types/test.ts delete mode 100644 examples/c/Makefile delete mode 100644 examples/c/example.c delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/broadcast_shapes.h create mode 100644 index.js create mode 100644 index.js.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 manifest.json delete mode 100644 src/main.c create mode 100644 stats_browser.html create mode 100644 stats_node.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 7f004ad..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 a07d970..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 0b95533..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: '0 12 * * 5' - - # 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 +``` -```javascript -var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); +If no recognized module system is present, access bundle contents via the global scope: + +```html + ``` #### broadcastShapes( shapes ) @@ -245,9 +251,14 @@ var sh = broadcastShapes( [ sh1, sh2 ] ); -```javascript -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); +```html + + + + + + + + ```
@@ -288,131 +304,7 @@ for ( i = 0; i < shapes.length; i++ ) { -* * * - -
- -## C APIs - - - -
- -
- - - - - -
- -### Usage - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -``` - -#### stdlib_ndarray_broadcast_shapes( M, \*\*shapes, \*ndims, \*out ) - -Broadcasts array shapes to a single shape. - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -int64_t N1 = 4; -int64_t sh1[] = { 8, 1, 6, 1 }; - -int64_t N2 = 3; -int64_t sh2[] = { 7, 1, 5 }; - -int64_t ndims[] = { N1, N2 }; -int64_t *shapes[] = { sh1, sh2 }; - -int64_t out[] = { 0, 0, 0, 0 }; -int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -if ( status != 0 ) { - // Handle error... -} -``` - -The function accepts the following arguments: - -- **M**: `[in] int64_t` number of shape arrays. -- **shapes**: `[in] int64_t**` array of shape arrays (dimensions). -- **ndims**: `[in] int64_t*` number of dimensions for each respective shape array. -- **out**: `[out] int64_t*` output shape array. - -```c -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ); -``` - -If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). - -
- - - - - -
- -### Notes - -- Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. - -
- - - - - -
- -### Examples - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main( void ) { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} -``` - -
- - - -
- 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.js b/benchmark/benchmark.js deleted file mode 100644 index 6426216..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,112 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pkg = require( './../package.json' ).name; -var broadcastShapes = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::two_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ] ], - [ [ 3, 2 ], [ 3, 1 ] ], - [ [ 1, 1 ], [ 2, 2 ] ], - [ [ 1 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::three_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::four_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ], [ 8, 1, 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ], [ 1, 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ], [ 1, 1, 2, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ], [ 1 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ], [ 5, 1, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/c/Makefile b/benchmark/c/Makefile deleted file mode 100644 index 5dc545c..0000000 --- a/benchmark/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := benchmark.out - - -# RULES # - -#/ -# Compiles C source files. -# -# @param {string} SOURCE_FILES - list of C source files -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lpthread -lblas`) -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [C_COMPILER] - C compiler -# @param {string} [CFLAGS] - C compiler flags -# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} SOURCE_FILES - list of C source files -# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {(string|void)} LIBRARIES - list of libraries (e.g., `-lpthread -lblas`) -# @param {(string|void)} LIBPATH - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} CC - C compiler -# @param {string} CFLAGS - C compiler flags -# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled benchmarks. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/benchmark/c/benchmark.c b/benchmark/c/benchmark.c deleted file mode 100644 index be62cd5..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,152 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/** -* Benchmark `broadcast_shapes`. -*/ -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "broadcast-shapes" -#define ITERATIONS 1000000 -#define REPEATS 3 - -/** -* Prints the TAP version. -*/ -void print_version() { - printf( "TAP version 13\n" ); -} - -/** -* Prints the TAP summary. -* -* @param total total number of tests -* @param passing total number of passing tests -*/ -void print_summary( int total, int passing ) { - printf( "#\n" ); - printf( "1..%d\n", total ); // TAP plan - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); -} - -/** -* Prints benchmarks results. -* -* @param elapsed elapsed time in seconds -*/ -void print_results( double elapsed ) { - double rate = (double)ITERATIONS / elapsed; - printf( " ---\n" ); - printf( " iterations: %d\n", ITERATIONS ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", rate ); - printf( " ...\n" ); -} - -/** -* Returns a clock time. -* -* @return clock time -*/ -double tic() { - struct timeval now; - gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; -} - -/** -* Generates a random double on the interval [0,1]. -* -* @return random double -*/ -double rand_double() { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark() { - double elapsed; - int8_t status; - double t; - int i; - - int64_t sh1[] = { 8, 1, 6, 1 }; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { 4, 3 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( out[ 0 ] != 8 ) { - printf( "unexpected result\n" ); - } - if ( out[ 1 ] != 7 ) { - printf( "unexpected result\n" ); - } - if ( out[ 2 ] != 6 ) { - printf( "unexpected result\n" ); - } - if ( out[ 3 ] != 5 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Main execution sequence. -*/ -int main( void ) { - double elapsed; - int i; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - for ( i = 0; i < REPEATS; i++ ) { - printf( "# c::native::%s::two_arrays\n", NAME ); - elapsed = benchmark(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", i+1 ); - } - print_summary( REPEATS, REPEATS ); -} diff --git a/branches.md b/branches.md deleted file mode 100644 index 79909c9..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes" -%% click B href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/blob/esm/README.md \ No newline at end of file diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..44a8074 --- /dev/null +++ b/browser.js @@ -0,0 +1,3 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map new file mode 100644 index 0000000..aa4b2bb --- /dev/null +++ b/browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"browser.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 87ea8b6..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import broadcastShapes from '../docs/types/index'; -export = broadcastShapes; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 625741a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var d=function(t,e){return function(){return e||t((e={exports:{}}).exports,e),e.exports}};var h=d(function(x,c){ -function g(t){var e,n,u,o,s,l,a,f,i,r,v;if(f=t.length,n=[],f===0)return n;if(o=t[0],i=o.length,f===1){for(r=0;ri&&(i=e[r]);for(r=0;r=0;){for(s=e[0]-i+r,s>=0?u=o[s]:u=1,v=1;v=0?a=t[v][l]:a=1,u===1){u=a;continue}if(!(a===1||u===a))return null}n[r]=u,r-=1}return n}c.exports=g -});var m=h();module.exports=m; -/** @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 db2949f..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = broadcastShapes;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast array shapes to a single shape.\n*\n* @module @stdlib/ndarray-base-broadcast-shapes\n*\n* @example\n* var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' );\n*\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\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,cAkLA,SAASC,EAAiBC,EAAS,CAClC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GAFAH,EAAIR,EAAO,OACXE,EAAM,CAAC,EACFM,IAAM,EACV,OAAON,EAMR,GAJAE,EAAKJ,EAAQ,CAAE,EACfS,EAAIL,EAAG,OAGFI,IAAM,EAAI,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAI,KAAME,EAAIM,CAAE,CAAE,EAEnB,OAAOR,CACR,CAGA,IADAD,EAAQ,CAAEQ,CAAE,EACNC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAM,KAAMD,EAAQU,CAAE,EAAE,MAAO,EAC1BT,EAAOS,CAAE,EAAID,IACjBA,EAAIR,EAAOS,CAAE,GAIf,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAI,KAAM,CAAE,EAIb,IADAQ,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IANAL,EAAKJ,EAAO,CAAE,EAAIQ,EAAIC,EACjBL,GAAM,EACVF,EAAMC,EAAIC,CAAG,EAEbF,EAAM,EAEDQ,EAAI,EAAGA,EAAIH,EAAGG,IAAM,CAOzB,GANAL,EAAKL,EAAOU,CAAE,EAAIF,EAAIC,EACjBJ,GAAM,EACVC,EAAIP,EAAQW,CAAE,EAAGL,CAAG,EAEpBC,EAAI,EAEAJ,IAAQ,EAAI,CAChBA,EAAMI,EACN,QACD,CACA,GAAK,EAAAA,IAAM,GAAKJ,IAAQI,GAKxB,OAAO,IACR,CACAL,EAAKQ,CAAE,EAAIP,EACXO,GAAK,CACN,CACA,OAAOR,CACR,CAKAJ,EAAO,QAAUC,ICxNjB,IAAIa,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "broadcastShapes", "shapes", "ndims", "out", "dim", "sh", "n1", "n2", "d", "M", "N", "i", "j", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f1d92f6..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,39 +0,0 @@ - -{{alias}}( shapes ) - Broadcasts array shapes to a single shape. - - Two respective dimensions in two shape arrays are compatible if - - 1. the dimensions are equal. - 2. one dimension is `1`. - - The function returns `null` if provided incompatible shapes (i.e., shapes - which cannot be broadcast with one another). - - Parameters - ---------- - shapes: Array - Array of shape arrays. - - Returns - ------- - out: Array|null - Broadcast shape. - - Examples - -------- - // Compatible shapes: - > var sh1 = [ 8, 1, 6, 1 ]; - > var sh2 = [ 7, 1, 5 ]; - > var sh = {{alias}}( [ sh1, sh2 ] ) - [ 8, 7, 6, 5 ] - - // Incompatible shapes: - > sh1 = [ 3, 2 ]; - > sh1 = [ 2, 3 ]; - > sh = {{alias}}( [ sh1, sh2 ] ) - null - - See Also - -------- - diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts deleted file mode 100644 index c2702cf..0000000 --- a/docs/types/index.d.ts +++ /dev/null @@ -1,177 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ArrayLike } from '@stdlib/types/array'; - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param shapes - array shapes -* @returns broadcast shape -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -declare function broadcastShapes( shapes: ArrayLike> ): ArrayLike; - - -// EXPORTS // - -export = broadcastShapes; diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 2886539..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 broadcastShapes = require( './index' ); - - -// TESTS // - -// The function returns an array of numbers... -{ - broadcastShapes( [ [ 1, 2 ], [ 2, 2 ] ] ); // $ExpectType ArrayLike -} - -// The compiler throws an error if the function is not provided an array-like object containing array-like objects containing numbers... -{ - broadcastShapes( '5' ); // $ExpectError - broadcastShapes( 5 ); // $ExpectError - broadcastShapes( true ); // $ExpectError - broadcastShapes( false ); // $ExpectError - broadcastShapes( null ); // $ExpectError - broadcastShapes( {} ); // $ExpectError - broadcastShapes( [ '5' ] ); // $ExpectError - broadcastShapes( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - broadcastShapes(); // $ExpectError - broadcastShapes( [ [ 1, 2, 3 ] ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/c/Makefile b/examples/c/Makefile deleted file mode 100644 index 70c91f4..0000000 --- a/examples/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := example.out - - -# RULES # - -#/ -# Compiles source files. -# -# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) -# @param {string} [CFLAGS] - C compiler options -# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) -# @param {string} [SOURCE_FILES] - list of source files -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} CC - C compiler (e.g., `gcc`) -# @param {string} CFLAGS - C compiler options -# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) -# @param {string} SOURCE_FILES - list of source files -# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) -# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled examples. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/examples/c/example.c b/examples/c/example.c deleted file mode 100644 index 4bc54d5..0000000 --- a/examples/c/example.c +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main( void ) { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 28811f9..0000000 --- a/examples/index.js +++ /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. -*/ - -'use strict'; - -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( './../lib' ); - -var shapes; -var out; -var sh; -var i; -var j; - -function shape2string( shape ) { - return lpad( shape.join( ' x ' ), 20, ' ' ); -} - -shapes = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] -]; - -for ( i = 0; i < shapes.length; i++ ) { - sh = shapes[ i ]; - for ( j = 0; j < sh.length; j++ ) { - console.log( shape2string( sh[ j ] ) ); - } - console.log( lpad( '', 20, '-' ) ); - - out = broadcastShapes( sh ); - console.log( shape2string( out )+'\n' ); -} diff --git a/include/stdlib/ndarray/base/broadcast_shapes.h b/include/stdlib/ndarray/base/broadcast_shapes.h deleted file mode 100644 index e23dce1..0000000 --- a/include/stdlib/ndarray/base/broadcast_shapes.h +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#ifndef STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H -#define STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H - -#include - -/* -* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. -*/ -#ifdef __cplusplus -extern "C" { -#endif - -/** -* Broadcasts array shapes to a single shape. -*/ -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H diff --git a/index.js b/index.js new file mode 100644 index 0000000..d225eb4 --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map new file mode 100644 index 0000000..0c02c0f --- /dev/null +++ b/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 0c9817e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Broadcast array shapes to a single shape. -* -* @module @stdlib/ndarray-base-broadcast-shapes -* -* @example -* var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); -* -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -*/ - -// 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 8558e60..0000000 --- a/lib/main.js +++ /dev/null @@ -1,256 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param {Array} shapes - array of shape arrays -* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`) -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [ 8, 0, 1, 6, 1 ], -* [ 8, 8, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -function broadcastShapes( shapes ) { - var ndims; - var out; - var dim; - var sh; - var n1; - var n2; - var d; - var M; - var N; - var i; - var j; - - M = shapes.length; - out = []; - if ( M === 0 ) { - return out; - } - sh = shapes[ 0 ]; - N = sh.length; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M === 1 ) { - // Need to manually copy to output shape, as shapes could be array-like objects... - for ( i = 0; i < N; i++ ) { - out.push( sh[ i ] ); - } - return out; - } - // Determine the maximum dimensionality... - ndims = [ N ]; - for ( i = 1; i < M; i++ ) { - ndims.push( shapes[ i ].length ); - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Initialize the output array... - for ( i = 0; i < N; i++ ) { - out.push( 0 ); - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim === 1 ) { - dim = d; - continue; - } - if ( d === 1 || dim === d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return null; - } - out[ i ] = dim; - i -= 1; - } - return out; -} - - -// EXPORTS // - -module.exports = broadcastShapes; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 890a937..0000000 --- a/manifest.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "options": {}, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [] - } - ] -} diff --git a/package.json b/package.json index c8b4d11..fe8bc85 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,7 @@ "version": "0.2.0", "description": "Broadcast array shapes to a single shape.", "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", - "include": "./include", - "lib": "./lib", - "src": "./src", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "main": "./index.js", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,33 +12,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/types": "^0.3.1", - "@stdlib/utils-library-manifest": "^0.2.0", - "@stdlib/error-tools-fmtprodmsg": "^0.2.0" - }, - "devDependencies": { - "@stdlib/string-left-pad": "^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", "stdtypes", @@ -80,9 +27,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 35a3654..0000000 --- a/src/main.c +++ /dev/null @@ -1,118 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). -* -* - Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. -* -* @param M number of array shapes -* @param shapes pointer to an array containing shape arrays -* @param ndims array containing the number of dimensions for (i.e., length of) each respective shape array -* @param out pointer to output array -* @return status -* -* @example -* #include "stdlib/ndarray/base/broadcast_shapes.h" -* #include -* -* int64_t N1 = 4; -* int64_t sh1[] = { 8, 1, 6, 1 }; -* -* int64_t N2 = 3; -* int64_t sh2[] = { 7, 1, 5 }; -* -* int64_t ndims[] = { N1, N2 }; -* int64_t *shapes[] = { sh1, sh2 }; -* -* int64_t out[] = { 0, 0, 0, 0 }; -* int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -*/ -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ) { - int64_t dim; - int64_t *sh; - int64_t n1; - int64_t n2; - int64_t d; - int64_t N; - int64_t i; - int64_t j; - - if ( M == 0 ) { - return 0; - } - sh = shapes[ 0 ]; - N = ndims[ 0 ]; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M == 1 ) { - for ( i = 0; i < N; i++ ) { - out[ i ] = sh[ i ]; - } - return 0; - } - // Determine the maximum dimensionality... - for ( i = 1; i < M; i++ ) { - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim == 1 ) { - dim = d; - continue; - } - if ( d == 1 || dim == d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return -1; - } - out[ i ] = dim; - i -= 1; - } - return 0; -} diff --git a/stats_browser.html b/stats_browser.html new file mode 100644 index 0000000..4f240d8 --- /dev/null +++ b/stats_browser.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/stats_node.html b/stats_node.html new file mode 100644 index 0000000..6fa2ba8 --- /dev/null +++ b/stats_node.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 63f703c..0000000 --- a/test/test.js +++ /dev/null @@ -1,230 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var broadcastShapes = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastShapes, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] - ]; - - expected = [ - [ 1, 2 ], - [ 3, 4 ], - [ 5, 6, 7 ], - [ 3, 3 ], - [ 3 ], - [ 3, 2 ], - [ 2, 3 ], - [ 1, 2 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty dims)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 0 ], [ 0, 0 ] ], - [ [ 0, 1 ], [ 0, 0 ] ], - [ [ 1, 0 ], [ 0, 1 ] ], - [ [ 1, 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 1, 0 ] ], - [ [ 1, 1 ], [ 0, 1 ] ], - [ [ 0 ], [ 0, 0 ] ], - [ [ 0 ], [ 0, 1 ] ], - [ [ 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 0 ] ], - [ [ 1 ], [ 0, 1 ] ], - [ [ 1 ], [ 1, 0 ] ], - [ [ 1 ], [ 8, 0 ] ], - [ [ 8, 1, 6, 1 ], [ 0, 1, 5 ] ], - [ [ 8, 0, 6, 1 ], [ 1, 5 ] ] - ]; - - expected = [ - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 1, 0 ], - [ 8, 0 ], - [ 8, 0, 6, 5 ], - [ 8, 0, 6, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (no shapes)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [] - ]; - - expected = [ - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty shapes (i.e., zero-dimensional array broadcasting))', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [] ], - [ [], [] ], - [ [], [], [] ], - [ [], [ 0 ] ], - [ [ 0 ], [] ], - [ [], [ 0, 0 ] ], - [ [ 0, 0 ], [] ], - [ [], [ 1, 0 ] ], - [ [], [ 0, 1 ] ], - [ [], [ 3, 3 ] ], - [ [], [ 3, 3 ], [] ] - ]; - - expected = [ - [], - [], - [], - [ 0 ], - [ 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 3, 3 ], - [ 3, 3 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (single shape)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 7 ] ], - [ [ 1, 1 ] ], - [ [ 5, 6, 1 ] ] - ]; - - expected = [ - [ 7 ], - [ 1, 1 ], - [ 5, 6, 1 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function returns `null` if provided incompatible shapes', function test( t ) { - var actual; - var values; - var i; - - values = [ - [ [ 3 ], [ 4 ] ], - [ [ 2, 3 ], [ 2 ] ], - [ [ 3 ], [ 3 ], [ 4 ] ], - [ [ 1, 3, 4 ], [ 2, 3, 3 ] ], - [ [ 1, 2 ], [ 3, 1 ], [ 3, 2 ], [ 10, 5 ] ], - [ [ 2 ], [ 2, 3 ] ], - [ [ 2 ], [ 2 ], [ 2 ], [ 2 ], [ 3 ], [ 3 ], [ 3 ], [ 3 ] ], - [ [ 9, 0, 9 ], [ 0, 9, 0 ] ], - [ [ 9, 9, 9 ], [ 0, 9, 9 ] ], - [ [ 9, 0, 9 ], [ 9, 9, 9 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 0 ] ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.strictEqual( actual, null, 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); From fcda72b0434fce0f7f3e37043b4b17ecc7b95ad0 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 14 Feb 2024 10:43:53 +0000 Subject: [PATCH 084/158] Update README.md for UMD bundle v0.2.0 --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 0be5417..0ba6b76 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ limitations under the License. To use in Observable, ```javascript -broadcastShapes = require( 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-shapes@umd/browser.js' ) +broadcastShapes = require( 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-shapes@v0.2.0-umd/browser.js' ) ``` To vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build: @@ -66,7 +66,7 @@ var broadcastShapes = require( 'path/to/vendor/umd/ndarray-base-broadcast-shapes To include the bundle in a webpage, ```html - + ``` If no recognized module system is present, access bundle contents via the global scope: @@ -256,7 +256,7 @@ var sh = broadcastShapes( [ sh1, sh2 ] ); - + + ``` If no recognized module system is present, access bundle contents via the global scope: @@ -256,7 +261,7 @@ var sh = broadcastShapes( [ sh1, sh2 ] ); - + - - - - diff --git a/stats_node.html b/stats_node.html deleted file mode 100644 index 6fa2ba8..0000000 --- a/stats_node.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 52fc0db6405e013bc8105d1fe2c882cb7bab929c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 22 Feb 2024 03:31:24 +0000 Subject: [PATCH 088/158] 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 | 178 +- SECURITY.md | 5 - benchmark/benchmark.js | 112 - benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 152 - branches.md | 56 - browser.js | 3 + browser.js.map | 1 + dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 39 - docs/types/index.d.ts | 177 - docs/types/test.ts | 45 - examples/c/Makefile | 146 - examples/c/example.c | 50 - examples/index.js | 54 - .../stdlib/ndarray/base/broadcast_shapes.h | 40 - index.js | 3 + index.js.map | 1 + lib/index.js | 45 - lib/main.js | 256 - manifest.json | 38 - package.json | 58 +- src/main.c | 118 - stats_browser.html | 4842 +++++++++++++++++ stats_node.html | 4842 +++++++++++++++++ test/dist/test.js | 33 - test/test.js | 230 - 52 files changed, 9729 insertions(+), 5117 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.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 branches.md create mode 100644 browser.js create mode 100644 browser.js.map 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/index.d.ts delete mode 100644 docs/types/test.ts delete mode 100644 examples/c/Makefile delete mode 100644 examples/c/example.c delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/broadcast_shapes.h create mode 100644 index.js create mode 100644 index.js.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 manifest.json delete mode 100644 src/main.c create mode 100644 stats_browser.html create mode 100644 stats_node.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 7f004ad..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 a07d970..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 7292af0..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: '0 12 * * 5' - - # 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 +``` -```javascript -var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); +If no recognized module system is present, access bundle contents via the global scope: + +```html + ``` #### broadcastShapes( shapes ) @@ -245,9 +251,14 @@ var sh = broadcastShapes( [ sh1, sh2 ] ); -```javascript -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); +```html + + + + + + + + ```
@@ -288,131 +304,7 @@ for ( i = 0; i < shapes.length; i++ ) { -* * * - -
- -## C APIs - - - -
- -
- - - - - -
- -### Usage - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -``` - -#### stdlib_ndarray_broadcast_shapes( M, \*\*shapes, \*ndims, \*out ) - -Broadcasts array shapes to a single shape. - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -int64_t N1 = 4; -int64_t sh1[] = { 8, 1, 6, 1 }; - -int64_t N2 = 3; -int64_t sh2[] = { 7, 1, 5 }; - -int64_t ndims[] = { N1, N2 }; -int64_t *shapes[] = { sh1, sh2 }; - -int64_t out[] = { 0, 0, 0, 0 }; -int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -if ( status != 0 ) { - // Handle error... -} -``` - -The function accepts the following arguments: - -- **M**: `[in] int64_t` number of shape arrays. -- **shapes**: `[in] int64_t**` array of shape arrays (dimensions). -- **ndims**: `[in] int64_t*` number of dimensions for each respective shape array. -- **out**: `[out] int64_t*` output shape array. - -```c -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ); -``` - -If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). - -
- - - - - -
- -### Notes - -- Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. - -
- - - - - -
- -### Examples - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main( void ) { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} -``` - -
- - - -
- 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.js b/benchmark/benchmark.js deleted file mode 100644 index 6426216..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,112 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pkg = require( './../package.json' ).name; -var broadcastShapes = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::two_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ] ], - [ [ 3, 2 ], [ 3, 1 ] ], - [ [ 1, 1 ], [ 2, 2 ] ], - [ [ 1 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::three_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::four_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ], [ 8, 1, 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ], [ 1, 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ], [ 1, 1, 2, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ], [ 1 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ], [ 5, 1, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/c/Makefile b/benchmark/c/Makefile deleted file mode 100644 index 5dc545c..0000000 --- a/benchmark/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := benchmark.out - - -# RULES # - -#/ -# Compiles C source files. -# -# @param {string} SOURCE_FILES - list of C source files -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lpthread -lblas`) -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [C_COMPILER] - C compiler -# @param {string} [CFLAGS] - C compiler flags -# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} SOURCE_FILES - list of C source files -# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {(string|void)} LIBRARIES - list of libraries (e.g., `-lpthread -lblas`) -# @param {(string|void)} LIBPATH - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} CC - C compiler -# @param {string} CFLAGS - C compiler flags -# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled benchmarks. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/benchmark/c/benchmark.c b/benchmark/c/benchmark.c deleted file mode 100644 index be62cd5..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,152 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/** -* Benchmark `broadcast_shapes`. -*/ -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "broadcast-shapes" -#define ITERATIONS 1000000 -#define REPEATS 3 - -/** -* Prints the TAP version. -*/ -void print_version() { - printf( "TAP version 13\n" ); -} - -/** -* Prints the TAP summary. -* -* @param total total number of tests -* @param passing total number of passing tests -*/ -void print_summary( int total, int passing ) { - printf( "#\n" ); - printf( "1..%d\n", total ); // TAP plan - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); -} - -/** -* Prints benchmarks results. -* -* @param elapsed elapsed time in seconds -*/ -void print_results( double elapsed ) { - double rate = (double)ITERATIONS / elapsed; - printf( " ---\n" ); - printf( " iterations: %d\n", ITERATIONS ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", rate ); - printf( " ...\n" ); -} - -/** -* Returns a clock time. -* -* @return clock time -*/ -double tic() { - struct timeval now; - gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; -} - -/** -* Generates a random double on the interval [0,1]. -* -* @return random double -*/ -double rand_double() { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark() { - double elapsed; - int8_t status; - double t; - int i; - - int64_t sh1[] = { 8, 1, 6, 1 }; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { 4, 3 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( out[ 0 ] != 8 ) { - printf( "unexpected result\n" ); - } - if ( out[ 1 ] != 7 ) { - printf( "unexpected result\n" ); - } - if ( out[ 2 ] != 6 ) { - printf( "unexpected result\n" ); - } - if ( out[ 3 ] != 5 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Main execution sequence. -*/ -int main( void ) { - double elapsed; - int i; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - for ( i = 0; i < REPEATS; i++ ) { - printf( "# c::native::%s::two_arrays\n", NAME ); - elapsed = benchmark(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", i+1 ); - } - print_summary( REPEATS, REPEATS ); -} diff --git a/branches.md b/branches.md deleted file mode 100644 index 79909c9..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes" -%% click B href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/blob/esm/README.md \ No newline at end of file diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..44a8074 --- /dev/null +++ b/browser.js @@ -0,0 +1,3 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map new file mode 100644 index 0000000..aa4b2bb --- /dev/null +++ b/browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"browser.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 87ea8b6..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import broadcastShapes from '../docs/types/index'; -export = broadcastShapes; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 625741a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var d=function(t,e){return function(){return e||t((e={exports:{}}).exports,e),e.exports}};var h=d(function(x,c){ -function g(t){var e,n,u,o,s,l,a,f,i,r,v;if(f=t.length,n=[],f===0)return n;if(o=t[0],i=o.length,f===1){for(r=0;ri&&(i=e[r]);for(r=0;r=0;){for(s=e[0]-i+r,s>=0?u=o[s]:u=1,v=1;v=0?a=t[v][l]:a=1,u===1){u=a;continue}if(!(a===1||u===a))return null}n[r]=u,r-=1}return n}c.exports=g -});var m=h();module.exports=m; -/** @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 db2949f..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = broadcastShapes;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast array shapes to a single shape.\n*\n* @module @stdlib/ndarray-base-broadcast-shapes\n*\n* @example\n* var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' );\n*\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\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,cAkLA,SAASC,EAAiBC,EAAS,CAClC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GAFAH,EAAIR,EAAO,OACXE,EAAM,CAAC,EACFM,IAAM,EACV,OAAON,EAMR,GAJAE,EAAKJ,EAAQ,CAAE,EACfS,EAAIL,EAAG,OAGFI,IAAM,EAAI,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAI,KAAME,EAAIM,CAAE,CAAE,EAEnB,OAAOR,CACR,CAGA,IADAD,EAAQ,CAAEQ,CAAE,EACNC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAM,KAAMD,EAAQU,CAAE,EAAE,MAAO,EAC1BT,EAAOS,CAAE,EAAID,IACjBA,EAAIR,EAAOS,CAAE,GAIf,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAI,KAAM,CAAE,EAIb,IADAQ,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IANAL,EAAKJ,EAAO,CAAE,EAAIQ,EAAIC,EACjBL,GAAM,EACVF,EAAMC,EAAIC,CAAG,EAEbF,EAAM,EAEDQ,EAAI,EAAGA,EAAIH,EAAGG,IAAM,CAOzB,GANAL,EAAKL,EAAOU,CAAE,EAAIF,EAAIC,EACjBJ,GAAM,EACVC,EAAIP,EAAQW,CAAE,EAAGL,CAAG,EAEpBC,EAAI,EAEAJ,IAAQ,EAAI,CAChBA,EAAMI,EACN,QACD,CACA,GAAK,EAAAA,IAAM,GAAKJ,IAAQI,GAKxB,OAAO,IACR,CACAL,EAAKQ,CAAE,EAAIP,EACXO,GAAK,CACN,CACA,OAAOR,CACR,CAKAJ,EAAO,QAAUC,ICxNjB,IAAIa,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "broadcastShapes", "shapes", "ndims", "out", "dim", "sh", "n1", "n2", "d", "M", "N", "i", "j", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f1d92f6..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,39 +0,0 @@ - -{{alias}}( shapes ) - Broadcasts array shapes to a single shape. - - Two respective dimensions in two shape arrays are compatible if - - 1. the dimensions are equal. - 2. one dimension is `1`. - - The function returns `null` if provided incompatible shapes (i.e., shapes - which cannot be broadcast with one another). - - Parameters - ---------- - shapes: Array - Array of shape arrays. - - Returns - ------- - out: Array|null - Broadcast shape. - - Examples - -------- - // Compatible shapes: - > var sh1 = [ 8, 1, 6, 1 ]; - > var sh2 = [ 7, 1, 5 ]; - > var sh = {{alias}}( [ sh1, sh2 ] ) - [ 8, 7, 6, 5 ] - - // Incompatible shapes: - > sh1 = [ 3, 2 ]; - > sh1 = [ 2, 3 ]; - > sh = {{alias}}( [ sh1, sh2 ] ) - null - - See Also - -------- - diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts deleted file mode 100644 index c2702cf..0000000 --- a/docs/types/index.d.ts +++ /dev/null @@ -1,177 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ArrayLike } from '@stdlib/types/array'; - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param shapes - array shapes -* @returns broadcast shape -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -declare function broadcastShapes( shapes: ArrayLike> ): ArrayLike; - - -// EXPORTS // - -export = broadcastShapes; diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 2886539..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 broadcastShapes = require( './index' ); - - -// TESTS // - -// The function returns an array of numbers... -{ - broadcastShapes( [ [ 1, 2 ], [ 2, 2 ] ] ); // $ExpectType ArrayLike -} - -// The compiler throws an error if the function is not provided an array-like object containing array-like objects containing numbers... -{ - broadcastShapes( '5' ); // $ExpectError - broadcastShapes( 5 ); // $ExpectError - broadcastShapes( true ); // $ExpectError - broadcastShapes( false ); // $ExpectError - broadcastShapes( null ); // $ExpectError - broadcastShapes( {} ); // $ExpectError - broadcastShapes( [ '5' ] ); // $ExpectError - broadcastShapes( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - broadcastShapes(); // $ExpectError - broadcastShapes( [ [ 1, 2, 3 ] ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/c/Makefile b/examples/c/Makefile deleted file mode 100644 index 70c91f4..0000000 --- a/examples/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := example.out - - -# RULES # - -#/ -# Compiles source files. -# -# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) -# @param {string} [CFLAGS] - C compiler options -# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) -# @param {string} [SOURCE_FILES] - list of source files -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} CC - C compiler (e.g., `gcc`) -# @param {string} CFLAGS - C compiler options -# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) -# @param {string} SOURCE_FILES - list of source files -# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) -# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled examples. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/examples/c/example.c b/examples/c/example.c deleted file mode 100644 index 4bc54d5..0000000 --- a/examples/c/example.c +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main( void ) { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 28811f9..0000000 --- a/examples/index.js +++ /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. -*/ - -'use strict'; - -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( './../lib' ); - -var shapes; -var out; -var sh; -var i; -var j; - -function shape2string( shape ) { - return lpad( shape.join( ' x ' ), 20, ' ' ); -} - -shapes = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] -]; - -for ( i = 0; i < shapes.length; i++ ) { - sh = shapes[ i ]; - for ( j = 0; j < sh.length; j++ ) { - console.log( shape2string( sh[ j ] ) ); - } - console.log( lpad( '', 20, '-' ) ); - - out = broadcastShapes( sh ); - console.log( shape2string( out )+'\n' ); -} diff --git a/include/stdlib/ndarray/base/broadcast_shapes.h b/include/stdlib/ndarray/base/broadcast_shapes.h deleted file mode 100644 index e23dce1..0000000 --- a/include/stdlib/ndarray/base/broadcast_shapes.h +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#ifndef STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H -#define STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H - -#include - -/* -* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. -*/ -#ifdef __cplusplus -extern "C" { -#endif - -/** -* Broadcasts array shapes to a single shape. -*/ -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H diff --git a/index.js b/index.js new file mode 100644 index 0000000..d225eb4 --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map new file mode 100644 index 0000000..0c02c0f --- /dev/null +++ b/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 0c9817e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Broadcast array shapes to a single shape. -* -* @module @stdlib/ndarray-base-broadcast-shapes -* -* @example -* var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); -* -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -*/ - -// 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 8558e60..0000000 --- a/lib/main.js +++ /dev/null @@ -1,256 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param {Array} shapes - array of shape arrays -* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`) -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [ 8, 0, 1, 6, 1 ], -* [ 8, 8, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -function broadcastShapes( shapes ) { - var ndims; - var out; - var dim; - var sh; - var n1; - var n2; - var d; - var M; - var N; - var i; - var j; - - M = shapes.length; - out = []; - if ( M === 0 ) { - return out; - } - sh = shapes[ 0 ]; - N = sh.length; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M === 1 ) { - // Need to manually copy to output shape, as shapes could be array-like objects... - for ( i = 0; i < N; i++ ) { - out.push( sh[ i ] ); - } - return out; - } - // Determine the maximum dimensionality... - ndims = [ N ]; - for ( i = 1; i < M; i++ ) { - ndims.push( shapes[ i ].length ); - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Initialize the output array... - for ( i = 0; i < N; i++ ) { - out.push( 0 ); - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim === 1 ) { - dim = d; - continue; - } - if ( d === 1 || dim === d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return null; - } - out[ i ] = dim; - i -= 1; - } - return out; -} - - -// EXPORTS // - -module.exports = broadcastShapes; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 890a937..0000000 --- a/manifest.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "options": {}, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [] - } - ] -} diff --git a/package.json b/package.json index 46477b4..0b77b65 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,7 @@ "version": "0.2.1", "description": "Broadcast array shapes to a single shape.", "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", - "include": "./include", - "lib": "./lib", - "src": "./src", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "main": "./index.js", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,33 +12,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/types": "^0.3.2", - "@stdlib/utils-library-manifest": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/string-left-pad": "^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", "stdtypes", @@ -80,9 +27,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 35a3654..0000000 --- a/src/main.c +++ /dev/null @@ -1,118 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). -* -* - Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. -* -* @param M number of array shapes -* @param shapes pointer to an array containing shape arrays -* @param ndims array containing the number of dimensions for (i.e., length of) each respective shape array -* @param out pointer to output array -* @return status -* -* @example -* #include "stdlib/ndarray/base/broadcast_shapes.h" -* #include -* -* int64_t N1 = 4; -* int64_t sh1[] = { 8, 1, 6, 1 }; -* -* int64_t N2 = 3; -* int64_t sh2[] = { 7, 1, 5 }; -* -* int64_t ndims[] = { N1, N2 }; -* int64_t *shapes[] = { sh1, sh2 }; -* -* int64_t out[] = { 0, 0, 0, 0 }; -* int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -*/ -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ) { - int64_t dim; - int64_t *sh; - int64_t n1; - int64_t n2; - int64_t d; - int64_t N; - int64_t i; - int64_t j; - - if ( M == 0 ) { - return 0; - } - sh = shapes[ 0 ]; - N = ndims[ 0 ]; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M == 1 ) { - for ( i = 0; i < N; i++ ) { - out[ i ] = sh[ i ]; - } - return 0; - } - // Determine the maximum dimensionality... - for ( i = 1; i < M; i++ ) { - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim == 1 ) { - dim = d; - continue; - } - if ( d == 1 || dim == d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return -1; - } - out[ i ] = dim; - i -= 1; - } - return 0; -} diff --git a/stats_browser.html b/stats_browser.html new file mode 100644 index 0000000..2f35700 --- /dev/null +++ b/stats_browser.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/stats_node.html b/stats_node.html new file mode 100644 index 0000000..c264c7d --- /dev/null +++ b/stats_node.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 63f703c..0000000 --- a/test/test.js +++ /dev/null @@ -1,230 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var broadcastShapes = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastShapes, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] - ]; - - expected = [ - [ 1, 2 ], - [ 3, 4 ], - [ 5, 6, 7 ], - [ 3, 3 ], - [ 3 ], - [ 3, 2 ], - [ 2, 3 ], - [ 1, 2 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty dims)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 0 ], [ 0, 0 ] ], - [ [ 0, 1 ], [ 0, 0 ] ], - [ [ 1, 0 ], [ 0, 1 ] ], - [ [ 1, 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 1, 0 ] ], - [ [ 1, 1 ], [ 0, 1 ] ], - [ [ 0 ], [ 0, 0 ] ], - [ [ 0 ], [ 0, 1 ] ], - [ [ 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 0 ] ], - [ [ 1 ], [ 0, 1 ] ], - [ [ 1 ], [ 1, 0 ] ], - [ [ 1 ], [ 8, 0 ] ], - [ [ 8, 1, 6, 1 ], [ 0, 1, 5 ] ], - [ [ 8, 0, 6, 1 ], [ 1, 5 ] ] - ]; - - expected = [ - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 1, 0 ], - [ 8, 0 ], - [ 8, 0, 6, 5 ], - [ 8, 0, 6, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (no shapes)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [] - ]; - - expected = [ - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty shapes (i.e., zero-dimensional array broadcasting))', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [] ], - [ [], [] ], - [ [], [], [] ], - [ [], [ 0 ] ], - [ [ 0 ], [] ], - [ [], [ 0, 0 ] ], - [ [ 0, 0 ], [] ], - [ [], [ 1, 0 ] ], - [ [], [ 0, 1 ] ], - [ [], [ 3, 3 ] ], - [ [], [ 3, 3 ], [] ] - ]; - - expected = [ - [], - [], - [], - [ 0 ], - [ 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 3, 3 ], - [ 3, 3 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (single shape)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 7 ] ], - [ [ 1, 1 ] ], - [ [ 5, 6, 1 ] ] - ]; - - expected = [ - [ 7 ], - [ 1, 1 ], - [ 5, 6, 1 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function returns `null` if provided incompatible shapes', function test( t ) { - var actual; - var values; - var i; - - values = [ - [ [ 3 ], [ 4 ] ], - [ [ 2, 3 ], [ 2 ] ], - [ [ 3 ], [ 3 ], [ 4 ] ], - [ [ 1, 3, 4 ], [ 2, 3, 3 ] ], - [ [ 1, 2 ], [ 3, 1 ], [ 3, 2 ], [ 10, 5 ] ], - [ [ 2 ], [ 2, 3 ] ], - [ [ 2 ], [ 2 ], [ 2 ], [ 2 ], [ 3 ], [ 3 ], [ 3 ], [ 3 ] ], - [ [ 9, 0, 9 ], [ 0, 9, 0 ] ], - [ [ 9, 9, 9 ], [ 0, 9, 9 ] ], - [ [ 9, 0, 9 ], [ 9, 9, 9 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 0 ] ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.strictEqual( actual, null, 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); From b7e874cb4c242243401a2f8018c97b633edb1d10 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 22 Feb 2024 03:54:03 +0000 Subject: [PATCH 089/158] Update README.md for UMD bundle v0.2.1 --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index d34a692..110968a 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ limitations under the License. To use in Observable, ```javascript -broadcastShapes = require( 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-shapes@umd/browser.js' ) +broadcastShapes = require( 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-shapes@v0.2.1-umd/browser.js' ) ``` To vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build: @@ -66,7 +66,7 @@ var broadcastShapes = require( 'path/to/vendor/umd/ndarray-base-broadcast-shapes To include the bundle in a webpage, ```html - + ``` If no recognized module system is present, access bundle contents via the global scope: @@ -256,7 +256,7 @@ var sh = broadcastShapes( [ sh1, sh2 ] ); - + + ``` If no recognized module system is present, access bundle contents via the global scope: @@ -256,7 +261,7 @@ var sh = broadcastShapes( [ sh1, sh2 ] ); - + - - - - diff --git a/stats_node.html b/stats_node.html deleted file mode 100644 index c264c7d..0000000 --- a/stats_node.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 2159dd33552308edf7770372d696290595cdb881 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Mar 2024 03:37:13 +0000 Subject: [PATCH 093/158] 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 | 178 +- SECURITY.md | 5 - benchmark/benchmark.js | 112 - benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 152 - branches.md | 56 - browser.js | 3 + browser.js.map | 1 + dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 39 - docs/types/index.d.ts | 177 - docs/types/test.ts | 45 - examples/c/Makefile | 146 - examples/c/example.c | 50 - examples/index.js | 54 - .../stdlib/ndarray/base/broadcast_shapes.h | 40 - index.js | 3 + index.js.map | 1 + lib/index.js | 45 - lib/main.js | 256 - manifest.json | 38 - package.json | 58 +- src/main.c | 118 - stats_browser.html | 4842 +++++++++++++++++ stats_node.html | 4842 +++++++++++++++++ test/dist/test.js | 33 - test/test.js | 230 - 53 files changed, 9729 insertions(+), 5119 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.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 branches.md create mode 100644 browser.js create mode 100644 browser.js.map 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/index.d.ts delete mode 100644 docs/types/test.ts delete mode 100644 examples/c/Makefile delete mode 100644 examples/c/example.c delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/broadcast_shapes.h create mode 100644 index.js create mode 100644 index.js.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 manifest.json delete mode 100644 src/main.c create mode 100644 stats_browser.html create mode 100644 stats_node.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 02f3a90..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-03-01T01:28:30.963Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 7f004ad..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 a07d970..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 7292af0..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: '0 12 * * 5' - - # 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 +``` -```javascript -var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); +If no recognized module system is present, access bundle contents via the global scope: + +```html + ``` #### broadcastShapes( shapes ) @@ -245,9 +251,14 @@ var sh = broadcastShapes( [ sh1, sh2 ] ); -```javascript -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); +```html + + + + + + + + ```
@@ -288,131 +304,7 @@ for ( i = 0; i < shapes.length; i++ ) { -* * * - -
- -## C APIs - - - -
- -
- - - - - -
- -### Usage - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -``` - -#### stdlib_ndarray_broadcast_shapes( M, \*\*shapes, \*ndims, \*out ) - -Broadcasts array shapes to a single shape. - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -int64_t N1 = 4; -int64_t sh1[] = { 8, 1, 6, 1 }; - -int64_t N2 = 3; -int64_t sh2[] = { 7, 1, 5 }; - -int64_t ndims[] = { N1, N2 }; -int64_t *shapes[] = { sh1, sh2 }; - -int64_t out[] = { 0, 0, 0, 0 }; -int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -if ( status != 0 ) { - // Handle error... -} -``` - -The function accepts the following arguments: - -- **M**: `[in] int64_t` number of shape arrays. -- **shapes**: `[in] int64_t**` array of shape arrays (dimensions). -- **ndims**: `[in] int64_t*` number of dimensions for each respective shape array. -- **out**: `[out] int64_t*` output shape array. - -```c -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ); -``` - -If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). - -
- - - - - -
- -### Notes - -- Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. - -
- - - - - -
- -### Examples - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main( void ) { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} -``` - -
- - - -
- 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.js b/benchmark/benchmark.js deleted file mode 100644 index 6426216..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,112 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pkg = require( './../package.json' ).name; -var broadcastShapes = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::two_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ] ], - [ [ 3, 2 ], [ 3, 1 ] ], - [ [ 1, 1 ], [ 2, 2 ] ], - [ [ 1 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::three_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::four_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ], [ 8, 1, 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ], [ 1, 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ], [ 1, 1, 2, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ], [ 1 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ], [ 5, 1, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/c/Makefile b/benchmark/c/Makefile deleted file mode 100644 index 5dc545c..0000000 --- a/benchmark/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := benchmark.out - - -# RULES # - -#/ -# Compiles C source files. -# -# @param {string} SOURCE_FILES - list of C source files -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lpthread -lblas`) -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [C_COMPILER] - C compiler -# @param {string} [CFLAGS] - C compiler flags -# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} SOURCE_FILES - list of C source files -# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {(string|void)} LIBRARIES - list of libraries (e.g., `-lpthread -lblas`) -# @param {(string|void)} LIBPATH - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} CC - C compiler -# @param {string} CFLAGS - C compiler flags -# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled benchmarks. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/benchmark/c/benchmark.c b/benchmark/c/benchmark.c deleted file mode 100644 index be62cd5..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,152 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/** -* Benchmark `broadcast_shapes`. -*/ -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "broadcast-shapes" -#define ITERATIONS 1000000 -#define REPEATS 3 - -/** -* Prints the TAP version. -*/ -void print_version() { - printf( "TAP version 13\n" ); -} - -/** -* Prints the TAP summary. -* -* @param total total number of tests -* @param passing total number of passing tests -*/ -void print_summary( int total, int passing ) { - printf( "#\n" ); - printf( "1..%d\n", total ); // TAP plan - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); -} - -/** -* Prints benchmarks results. -* -* @param elapsed elapsed time in seconds -*/ -void print_results( double elapsed ) { - double rate = (double)ITERATIONS / elapsed; - printf( " ---\n" ); - printf( " iterations: %d\n", ITERATIONS ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", rate ); - printf( " ...\n" ); -} - -/** -* Returns a clock time. -* -* @return clock time -*/ -double tic() { - struct timeval now; - gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; -} - -/** -* Generates a random double on the interval [0,1]. -* -* @return random double -*/ -double rand_double() { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark() { - double elapsed; - int8_t status; - double t; - int i; - - int64_t sh1[] = { 8, 1, 6, 1 }; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { 4, 3 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( out[ 0 ] != 8 ) { - printf( "unexpected result\n" ); - } - if ( out[ 1 ] != 7 ) { - printf( "unexpected result\n" ); - } - if ( out[ 2 ] != 6 ) { - printf( "unexpected result\n" ); - } - if ( out[ 3 ] != 5 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Main execution sequence. -*/ -int main( void ) { - double elapsed; - int i; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - for ( i = 0; i < REPEATS; i++ ) { - printf( "# c::native::%s::two_arrays\n", NAME ); - elapsed = benchmark(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", i+1 ); - } - print_summary( REPEATS, REPEATS ); -} diff --git a/branches.md b/branches.md deleted file mode 100644 index 79909c9..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes" -%% click B href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/blob/esm/README.md \ No newline at end of file diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..44a8074 --- /dev/null +++ b/browser.js @@ -0,0 +1,3 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map new file mode 100644 index 0000000..aa4b2bb --- /dev/null +++ b/browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"browser.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 87ea8b6..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import broadcastShapes from '../docs/types/index'; -export = broadcastShapes; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 625741a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var d=function(t,e){return function(){return e||t((e={exports:{}}).exports,e),e.exports}};var h=d(function(x,c){ -function g(t){var e,n,u,o,s,l,a,f,i,r,v;if(f=t.length,n=[],f===0)return n;if(o=t[0],i=o.length,f===1){for(r=0;ri&&(i=e[r]);for(r=0;r=0;){for(s=e[0]-i+r,s>=0?u=o[s]:u=1,v=1;v=0?a=t[v][l]:a=1,u===1){u=a;continue}if(!(a===1||u===a))return null}n[r]=u,r-=1}return n}c.exports=g -});var m=h();module.exports=m; -/** @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 db2949f..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = broadcastShapes;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast array shapes to a single shape.\n*\n* @module @stdlib/ndarray-base-broadcast-shapes\n*\n* @example\n* var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' );\n*\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\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,cAkLA,SAASC,EAAiBC,EAAS,CAClC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GAFAH,EAAIR,EAAO,OACXE,EAAM,CAAC,EACFM,IAAM,EACV,OAAON,EAMR,GAJAE,EAAKJ,EAAQ,CAAE,EACfS,EAAIL,EAAG,OAGFI,IAAM,EAAI,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAI,KAAME,EAAIM,CAAE,CAAE,EAEnB,OAAOR,CACR,CAGA,IADAD,EAAQ,CAAEQ,CAAE,EACNC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAM,KAAMD,EAAQU,CAAE,EAAE,MAAO,EAC1BT,EAAOS,CAAE,EAAID,IACjBA,EAAIR,EAAOS,CAAE,GAIf,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAI,KAAM,CAAE,EAIb,IADAQ,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IANAL,EAAKJ,EAAO,CAAE,EAAIQ,EAAIC,EACjBL,GAAM,EACVF,EAAMC,EAAIC,CAAG,EAEbF,EAAM,EAEDQ,EAAI,EAAGA,EAAIH,EAAGG,IAAM,CAOzB,GANAL,EAAKL,EAAOU,CAAE,EAAIF,EAAIC,EACjBJ,GAAM,EACVC,EAAIP,EAAQW,CAAE,EAAGL,CAAG,EAEpBC,EAAI,EAEAJ,IAAQ,EAAI,CAChBA,EAAMI,EACN,QACD,CACA,GAAK,EAAAA,IAAM,GAAKJ,IAAQI,GAKxB,OAAO,IACR,CACAL,EAAKQ,CAAE,EAAIP,EACXO,GAAK,CACN,CACA,OAAOR,CACR,CAKAJ,EAAO,QAAUC,ICxNjB,IAAIa,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "broadcastShapes", "shapes", "ndims", "out", "dim", "sh", "n1", "n2", "d", "M", "N", "i", "j", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f1d92f6..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,39 +0,0 @@ - -{{alias}}( shapes ) - Broadcasts array shapes to a single shape. - - Two respective dimensions in two shape arrays are compatible if - - 1. the dimensions are equal. - 2. one dimension is `1`. - - The function returns `null` if provided incompatible shapes (i.e., shapes - which cannot be broadcast with one another). - - Parameters - ---------- - shapes: Array - Array of shape arrays. - - Returns - ------- - out: Array|null - Broadcast shape. - - Examples - -------- - // Compatible shapes: - > var sh1 = [ 8, 1, 6, 1 ]; - > var sh2 = [ 7, 1, 5 ]; - > var sh = {{alias}}( [ sh1, sh2 ] ) - [ 8, 7, 6, 5 ] - - // Incompatible shapes: - > sh1 = [ 3, 2 ]; - > sh1 = [ 2, 3 ]; - > sh = {{alias}}( [ sh1, sh2 ] ) - null - - See Also - -------- - diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts deleted file mode 100644 index c2702cf..0000000 --- a/docs/types/index.d.ts +++ /dev/null @@ -1,177 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ArrayLike } from '@stdlib/types/array'; - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param shapes - array shapes -* @returns broadcast shape -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -declare function broadcastShapes( shapes: ArrayLike> ): ArrayLike; - - -// EXPORTS // - -export = broadcastShapes; diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 2886539..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 broadcastShapes = require( './index' ); - - -// TESTS // - -// The function returns an array of numbers... -{ - broadcastShapes( [ [ 1, 2 ], [ 2, 2 ] ] ); // $ExpectType ArrayLike -} - -// The compiler throws an error if the function is not provided an array-like object containing array-like objects containing numbers... -{ - broadcastShapes( '5' ); // $ExpectError - broadcastShapes( 5 ); // $ExpectError - broadcastShapes( true ); // $ExpectError - broadcastShapes( false ); // $ExpectError - broadcastShapes( null ); // $ExpectError - broadcastShapes( {} ); // $ExpectError - broadcastShapes( [ '5' ] ); // $ExpectError - broadcastShapes( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - broadcastShapes(); // $ExpectError - broadcastShapes( [ [ 1, 2, 3 ] ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/c/Makefile b/examples/c/Makefile deleted file mode 100644 index 70c91f4..0000000 --- a/examples/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := example.out - - -# RULES # - -#/ -# Compiles source files. -# -# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) -# @param {string} [CFLAGS] - C compiler options -# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) -# @param {string} [SOURCE_FILES] - list of source files -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} CC - C compiler (e.g., `gcc`) -# @param {string} CFLAGS - C compiler options -# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) -# @param {string} SOURCE_FILES - list of source files -# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) -# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled examples. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/examples/c/example.c b/examples/c/example.c deleted file mode 100644 index 4bc54d5..0000000 --- a/examples/c/example.c +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main( void ) { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 28811f9..0000000 --- a/examples/index.js +++ /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. -*/ - -'use strict'; - -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( './../lib' ); - -var shapes; -var out; -var sh; -var i; -var j; - -function shape2string( shape ) { - return lpad( shape.join( ' x ' ), 20, ' ' ); -} - -shapes = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] -]; - -for ( i = 0; i < shapes.length; i++ ) { - sh = shapes[ i ]; - for ( j = 0; j < sh.length; j++ ) { - console.log( shape2string( sh[ j ] ) ); - } - console.log( lpad( '', 20, '-' ) ); - - out = broadcastShapes( sh ); - console.log( shape2string( out )+'\n' ); -} diff --git a/include/stdlib/ndarray/base/broadcast_shapes.h b/include/stdlib/ndarray/base/broadcast_shapes.h deleted file mode 100644 index e23dce1..0000000 --- a/include/stdlib/ndarray/base/broadcast_shapes.h +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#ifndef STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H -#define STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H - -#include - -/* -* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. -*/ -#ifdef __cplusplus -extern "C" { -#endif - -/** -* Broadcasts array shapes to a single shape. -*/ -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H diff --git a/index.js b/index.js new file mode 100644 index 0000000..d225eb4 --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map new file mode 100644 index 0000000..0c02c0f --- /dev/null +++ b/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 0c9817e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Broadcast array shapes to a single shape. -* -* @module @stdlib/ndarray-base-broadcast-shapes -* -* @example -* var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); -* -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -*/ - -// 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 8558e60..0000000 --- a/lib/main.js +++ /dev/null @@ -1,256 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param {Array} shapes - array of shape arrays -* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`) -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [ 8, 0, 1, 6, 1 ], -* [ 8, 8, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -function broadcastShapes( shapes ) { - var ndims; - var out; - var dim; - var sh; - var n1; - var n2; - var d; - var M; - var N; - var i; - var j; - - M = shapes.length; - out = []; - if ( M === 0 ) { - return out; - } - sh = shapes[ 0 ]; - N = sh.length; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M === 1 ) { - // Need to manually copy to output shape, as shapes could be array-like objects... - for ( i = 0; i < N; i++ ) { - out.push( sh[ i ] ); - } - return out; - } - // Determine the maximum dimensionality... - ndims = [ N ]; - for ( i = 1; i < M; i++ ) { - ndims.push( shapes[ i ].length ); - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Initialize the output array... - for ( i = 0; i < N; i++ ) { - out.push( 0 ); - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim === 1 ) { - dim = d; - continue; - } - if ( d === 1 || dim === d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return null; - } - out[ i ] = dim; - i -= 1; - } - return out; -} - - -// EXPORTS // - -module.exports = broadcastShapes; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 890a937..0000000 --- a/manifest.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "options": {}, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [] - } - ] -} diff --git a/package.json b/package.json index a53e06e..0b77b65 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,7 @@ "version": "0.2.1", "description": "Broadcast array shapes to a single shape.", "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", - "include": "./include", - "lib": "./lib", - "src": "./src", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "main": "./index.js", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,33 +12,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/types": "^0.3.2", - "@stdlib/utils-library-manifest": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/string-left-pad": "^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", "stdtypes", @@ -80,9 +27,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 35a3654..0000000 --- a/src/main.c +++ /dev/null @@ -1,118 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). -* -* - Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. -* -* @param M number of array shapes -* @param shapes pointer to an array containing shape arrays -* @param ndims array containing the number of dimensions for (i.e., length of) each respective shape array -* @param out pointer to output array -* @return status -* -* @example -* #include "stdlib/ndarray/base/broadcast_shapes.h" -* #include -* -* int64_t N1 = 4; -* int64_t sh1[] = { 8, 1, 6, 1 }; -* -* int64_t N2 = 3; -* int64_t sh2[] = { 7, 1, 5 }; -* -* int64_t ndims[] = { N1, N2 }; -* int64_t *shapes[] = { sh1, sh2 }; -* -* int64_t out[] = { 0, 0, 0, 0 }; -* int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -*/ -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ) { - int64_t dim; - int64_t *sh; - int64_t n1; - int64_t n2; - int64_t d; - int64_t N; - int64_t i; - int64_t j; - - if ( M == 0 ) { - return 0; - } - sh = shapes[ 0 ]; - N = ndims[ 0 ]; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M == 1 ) { - for ( i = 0; i < N; i++ ) { - out[ i ] = sh[ i ]; - } - return 0; - } - // Determine the maximum dimensionality... - for ( i = 1; i < M; i++ ) { - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim == 1 ) { - dim = d; - continue; - } - if ( d == 1 || dim == d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return -1; - } - out[ i ] = dim; - i -= 1; - } - return 0; -} diff --git a/stats_browser.html b/stats_browser.html new file mode 100644 index 0000000..2f35700 --- /dev/null +++ b/stats_browser.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/stats_node.html b/stats_node.html new file mode 100644 index 0000000..c264c7d --- /dev/null +++ b/stats_node.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 63f703c..0000000 --- a/test/test.js +++ /dev/null @@ -1,230 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var broadcastShapes = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastShapes, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] - ]; - - expected = [ - [ 1, 2 ], - [ 3, 4 ], - [ 5, 6, 7 ], - [ 3, 3 ], - [ 3 ], - [ 3, 2 ], - [ 2, 3 ], - [ 1, 2 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty dims)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 0 ], [ 0, 0 ] ], - [ [ 0, 1 ], [ 0, 0 ] ], - [ [ 1, 0 ], [ 0, 1 ] ], - [ [ 1, 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 1, 0 ] ], - [ [ 1, 1 ], [ 0, 1 ] ], - [ [ 0 ], [ 0, 0 ] ], - [ [ 0 ], [ 0, 1 ] ], - [ [ 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 0 ] ], - [ [ 1 ], [ 0, 1 ] ], - [ [ 1 ], [ 1, 0 ] ], - [ [ 1 ], [ 8, 0 ] ], - [ [ 8, 1, 6, 1 ], [ 0, 1, 5 ] ], - [ [ 8, 0, 6, 1 ], [ 1, 5 ] ] - ]; - - expected = [ - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 1, 0 ], - [ 8, 0 ], - [ 8, 0, 6, 5 ], - [ 8, 0, 6, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (no shapes)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [] - ]; - - expected = [ - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty shapes (i.e., zero-dimensional array broadcasting))', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [] ], - [ [], [] ], - [ [], [], [] ], - [ [], [ 0 ] ], - [ [ 0 ], [] ], - [ [], [ 0, 0 ] ], - [ [ 0, 0 ], [] ], - [ [], [ 1, 0 ] ], - [ [], [ 0, 1 ] ], - [ [], [ 3, 3 ] ], - [ [], [ 3, 3 ], [] ] - ]; - - expected = [ - [], - [], - [], - [ 0 ], - [ 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 3, 3 ], - [ 3, 3 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (single shape)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 7 ] ], - [ [ 1, 1 ] ], - [ [ 5, 6, 1 ] ] - ]; - - expected = [ - [ 7 ], - [ 1, 1 ], - [ 5, 6, 1 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function returns `null` if provided incompatible shapes', function test( t ) { - var actual; - var values; - var i; - - values = [ - [ [ 3 ], [ 4 ] ], - [ [ 2, 3 ], [ 2 ] ], - [ [ 3 ], [ 3 ], [ 4 ] ], - [ [ 1, 3, 4 ], [ 2, 3, 3 ] ], - [ [ 1, 2 ], [ 3, 1 ], [ 3, 2 ], [ 10, 5 ] ], - [ [ 2 ], [ 2, 3 ] ], - [ [ 2 ], [ 2 ], [ 2 ], [ 2 ], [ 3 ], [ 3 ], [ 3 ], [ 3 ] ], - [ [ 9, 0, 9 ], [ 0, 9, 0 ] ], - [ [ 9, 9, 9 ], [ 0, 9, 9 ] ], - [ [ 9, 0, 9 ], [ 9, 9, 9 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 0 ] ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.strictEqual( actual, null, 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); From 18a53ed4570fded8a646ba2e3ac2dfcf8c9e5d3f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 01:45:26 +0000 Subject: [PATCH 094/158] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index e256077..a53e06e 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,8 @@ }, "dependencies": { "@stdlib/types": "^0.3.2", - "@stdlib/utils-library-manifest": "^0.2.1" + "@stdlib/utils-library-manifest": "^0.2.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1" }, "devDependencies": { "@stdlib/string-left-pad": "^0.2.1", @@ -84,4 +85,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From 9bc8fa960ae7b9d103ad286eb424e580c77fe987 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 03:57:28 +0000 Subject: [PATCH 095/158] Remove files --- browser.js | 3 - browser.js.map | 1 - index.js | 3 - index.js.map | 1 - stats_browser.html | 4842 -------------------------------------------- stats_node.html | 4842 -------------------------------------------- 6 files changed, 9692 deletions(-) delete mode 100644 browser.js delete mode 100644 browser.js.map delete mode 100644 index.js delete mode 100644 index.js.map delete mode 100644 stats_browser.html delete mode 100644 stats_node.html diff --git a/browser.js b/browser.js deleted file mode 100644 index 44a8074..0000000 --- a/browser.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); -//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map deleted file mode 100644 index aa4b2bb..0000000 --- a/browser.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"browser.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/index.js b/index.js deleted file mode 100644 index d225eb4..0000000 --- a/index.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); -//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map deleted file mode 100644 index 0c02c0f..0000000 --- a/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/stats_browser.html b/stats_browser.html deleted file mode 100644 index 2f35700..0000000 --- a/stats_browser.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - diff --git a/stats_node.html b/stats_node.html deleted file mode 100644 index c264c7d..0000000 --- a/stats_node.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From bdafcd7969f86810018e4bacdf87793426f0212a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 03:57:40 +0000 Subject: [PATCH 096/158] 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 | 178 +- SECURITY.md | 5 - benchmark/benchmark.js | 112 - benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 152 - branches.md | 56 - browser.js | 3 + browser.js.map | 1 + dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 39 - docs/types/index.d.ts | 177 - docs/types/test.ts | 45 - examples/c/Makefile | 146 - examples/c/example.c | 50 - examples/index.js | 54 - .../stdlib/ndarray/base/broadcast_shapes.h | 40 - index.js | 3 + index.js.map | 1 + lib/index.js | 45 - lib/main.js | 256 - manifest.json | 38 - package.json | 58 +- src/main.c | 118 - stats_browser.html | 4842 +++++++++++++++++ stats_node.html | 4842 +++++++++++++++++ test/dist/test.js | 33 - test/test.js | 230 - 53 files changed, 9729 insertions(+), 5122 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.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 branches.md create mode 100644 browser.js create mode 100644 browser.js.map 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/index.d.ts delete mode 100644 docs/types/test.ts delete mode 100644 examples/c/Makefile delete mode 100644 examples/c/example.c delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/broadcast_shapes.h create mode 100644 index.js create mode 100644 index.js.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 manifest.json delete mode 100644 src/main.c create mode 100644 stats_browser.html create mode 100644 stats_node.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 7f728c6..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-04-01T01:16:03.959Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 7f004ad..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 a07d970..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 7292af0..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: '0 12 * * 5' - - # 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 +``` -```javascript -var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); +If no recognized module system is present, access bundle contents via the global scope: + +```html + ``` #### broadcastShapes( shapes ) @@ -245,9 +251,14 @@ var sh = broadcastShapes( [ sh1, sh2 ] ); -```javascript -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); +```html + + + + + + + + ```
@@ -288,131 +304,7 @@ for ( i = 0; i < shapes.length; i++ ) { -* * * - -
- -## C APIs - - - -
- -
- - - - - -
- -### Usage - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -``` - -#### stdlib_ndarray_broadcast_shapes( M, \*\*shapes, \*ndims, \*out ) - -Broadcasts array shapes to a single shape. - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -int64_t N1 = 4; -int64_t sh1[] = { 8, 1, 6, 1 }; - -int64_t N2 = 3; -int64_t sh2[] = { 7, 1, 5 }; - -int64_t ndims[] = { N1, N2 }; -int64_t *shapes[] = { sh1, sh2 }; - -int64_t out[] = { 0, 0, 0, 0 }; -int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -if ( status != 0 ) { - // Handle error... -} -``` - -The function accepts the following arguments: - -- **M**: `[in] int64_t` number of shape arrays. -- **shapes**: `[in] int64_t**` array of shape arrays (dimensions). -- **ndims**: `[in] int64_t*` number of dimensions for each respective shape array. -- **out**: `[out] int64_t*` output shape array. - -```c -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ); -``` - -If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). - -
- - - - - -
- -### Notes - -- Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. - -
- - - - - -
- -### Examples - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main( void ) { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} -``` - -
- - - -
- 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.js b/benchmark/benchmark.js deleted file mode 100644 index 6426216..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,112 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pkg = require( './../package.json' ).name; -var broadcastShapes = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::two_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ] ], - [ [ 3, 2 ], [ 3, 1 ] ], - [ [ 1, 1 ], [ 2, 2 ] ], - [ [ 1 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::three_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::four_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ], [ 8, 1, 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ], [ 1, 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ], [ 1, 1, 2, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ], [ 1 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ], [ 5, 1, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/c/Makefile b/benchmark/c/Makefile deleted file mode 100644 index 5dc545c..0000000 --- a/benchmark/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := benchmark.out - - -# RULES # - -#/ -# Compiles C source files. -# -# @param {string} SOURCE_FILES - list of C source files -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lpthread -lblas`) -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [C_COMPILER] - C compiler -# @param {string} [CFLAGS] - C compiler flags -# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} SOURCE_FILES - list of C source files -# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {(string|void)} LIBRARIES - list of libraries (e.g., `-lpthread -lblas`) -# @param {(string|void)} LIBPATH - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} CC - C compiler -# @param {string} CFLAGS - C compiler flags -# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled benchmarks. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/benchmark/c/benchmark.c b/benchmark/c/benchmark.c deleted file mode 100644 index be62cd5..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,152 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/** -* Benchmark `broadcast_shapes`. -*/ -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "broadcast-shapes" -#define ITERATIONS 1000000 -#define REPEATS 3 - -/** -* Prints the TAP version. -*/ -void print_version() { - printf( "TAP version 13\n" ); -} - -/** -* Prints the TAP summary. -* -* @param total total number of tests -* @param passing total number of passing tests -*/ -void print_summary( int total, int passing ) { - printf( "#\n" ); - printf( "1..%d\n", total ); // TAP plan - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); -} - -/** -* Prints benchmarks results. -* -* @param elapsed elapsed time in seconds -*/ -void print_results( double elapsed ) { - double rate = (double)ITERATIONS / elapsed; - printf( " ---\n" ); - printf( " iterations: %d\n", ITERATIONS ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", rate ); - printf( " ...\n" ); -} - -/** -* Returns a clock time. -* -* @return clock time -*/ -double tic() { - struct timeval now; - gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; -} - -/** -* Generates a random double on the interval [0,1]. -* -* @return random double -*/ -double rand_double() { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark() { - double elapsed; - int8_t status; - double t; - int i; - - int64_t sh1[] = { 8, 1, 6, 1 }; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { 4, 3 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( out[ 0 ] != 8 ) { - printf( "unexpected result\n" ); - } - if ( out[ 1 ] != 7 ) { - printf( "unexpected result\n" ); - } - if ( out[ 2 ] != 6 ) { - printf( "unexpected result\n" ); - } - if ( out[ 3 ] != 5 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Main execution sequence. -*/ -int main( void ) { - double elapsed; - int i; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - for ( i = 0; i < REPEATS; i++ ) { - printf( "# c::native::%s::two_arrays\n", NAME ); - elapsed = benchmark(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", i+1 ); - } - print_summary( REPEATS, REPEATS ); -} diff --git a/branches.md b/branches.md deleted file mode 100644 index 79909c9..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes" -%% click B href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/blob/esm/README.md \ No newline at end of file diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..44a8074 --- /dev/null +++ b/browser.js @@ -0,0 +1,3 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map new file mode 100644 index 0000000..aa4b2bb --- /dev/null +++ b/browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"browser.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 87ea8b6..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import broadcastShapes from '../docs/types/index'; -export = broadcastShapes; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 625741a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var d=function(t,e){return function(){return e||t((e={exports:{}}).exports,e),e.exports}};var h=d(function(x,c){ -function g(t){var e,n,u,o,s,l,a,f,i,r,v;if(f=t.length,n=[],f===0)return n;if(o=t[0],i=o.length,f===1){for(r=0;ri&&(i=e[r]);for(r=0;r=0;){for(s=e[0]-i+r,s>=0?u=o[s]:u=1,v=1;v=0?a=t[v][l]:a=1,u===1){u=a;continue}if(!(a===1||u===a))return null}n[r]=u,r-=1}return n}c.exports=g -});var m=h();module.exports=m; -/** @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 db2949f..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = broadcastShapes;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast array shapes to a single shape.\n*\n* @module @stdlib/ndarray-base-broadcast-shapes\n*\n* @example\n* var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' );\n*\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\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,cAkLA,SAASC,EAAiBC,EAAS,CAClC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GAFAH,EAAIR,EAAO,OACXE,EAAM,CAAC,EACFM,IAAM,EACV,OAAON,EAMR,GAJAE,EAAKJ,EAAQ,CAAE,EACfS,EAAIL,EAAG,OAGFI,IAAM,EAAI,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAI,KAAME,EAAIM,CAAE,CAAE,EAEnB,OAAOR,CACR,CAGA,IADAD,EAAQ,CAAEQ,CAAE,EACNC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAM,KAAMD,EAAQU,CAAE,EAAE,MAAO,EAC1BT,EAAOS,CAAE,EAAID,IACjBA,EAAIR,EAAOS,CAAE,GAIf,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAI,KAAM,CAAE,EAIb,IADAQ,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IANAL,EAAKJ,EAAO,CAAE,EAAIQ,EAAIC,EACjBL,GAAM,EACVF,EAAMC,EAAIC,CAAG,EAEbF,EAAM,EAEDQ,EAAI,EAAGA,EAAIH,EAAGG,IAAM,CAOzB,GANAL,EAAKL,EAAOU,CAAE,EAAIF,EAAIC,EACjBJ,GAAM,EACVC,EAAIP,EAAQW,CAAE,EAAGL,CAAG,EAEpBC,EAAI,EAEAJ,IAAQ,EAAI,CAChBA,EAAMI,EACN,QACD,CACA,GAAK,EAAAA,IAAM,GAAKJ,IAAQI,GAKxB,OAAO,IACR,CACAL,EAAKQ,CAAE,EAAIP,EACXO,GAAK,CACN,CACA,OAAOR,CACR,CAKAJ,EAAO,QAAUC,ICxNjB,IAAIa,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "broadcastShapes", "shapes", "ndims", "out", "dim", "sh", "n1", "n2", "d", "M", "N", "i", "j", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f1d92f6..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,39 +0,0 @@ - -{{alias}}( shapes ) - Broadcasts array shapes to a single shape. - - Two respective dimensions in two shape arrays are compatible if - - 1. the dimensions are equal. - 2. one dimension is `1`. - - The function returns `null` if provided incompatible shapes (i.e., shapes - which cannot be broadcast with one another). - - Parameters - ---------- - shapes: Array - Array of shape arrays. - - Returns - ------- - out: Array|null - Broadcast shape. - - Examples - -------- - // Compatible shapes: - > var sh1 = [ 8, 1, 6, 1 ]; - > var sh2 = [ 7, 1, 5 ]; - > var sh = {{alias}}( [ sh1, sh2 ] ) - [ 8, 7, 6, 5 ] - - // Incompatible shapes: - > sh1 = [ 3, 2 ]; - > sh1 = [ 2, 3 ]; - > sh = {{alias}}( [ sh1, sh2 ] ) - null - - See Also - -------- - diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts deleted file mode 100644 index c2702cf..0000000 --- a/docs/types/index.d.ts +++ /dev/null @@ -1,177 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ArrayLike } from '@stdlib/types/array'; - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param shapes - array shapes -* @returns broadcast shape -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -declare function broadcastShapes( shapes: ArrayLike> ): ArrayLike; - - -// EXPORTS // - -export = broadcastShapes; diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 2886539..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 broadcastShapes = require( './index' ); - - -// TESTS // - -// The function returns an array of numbers... -{ - broadcastShapes( [ [ 1, 2 ], [ 2, 2 ] ] ); // $ExpectType ArrayLike -} - -// The compiler throws an error if the function is not provided an array-like object containing array-like objects containing numbers... -{ - broadcastShapes( '5' ); // $ExpectError - broadcastShapes( 5 ); // $ExpectError - broadcastShapes( true ); // $ExpectError - broadcastShapes( false ); // $ExpectError - broadcastShapes( null ); // $ExpectError - broadcastShapes( {} ); // $ExpectError - broadcastShapes( [ '5' ] ); // $ExpectError - broadcastShapes( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - broadcastShapes(); // $ExpectError - broadcastShapes( [ [ 1, 2, 3 ] ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/c/Makefile b/examples/c/Makefile deleted file mode 100644 index 70c91f4..0000000 --- a/examples/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := example.out - - -# RULES # - -#/ -# Compiles source files. -# -# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) -# @param {string} [CFLAGS] - C compiler options -# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) -# @param {string} [SOURCE_FILES] - list of source files -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} CC - C compiler (e.g., `gcc`) -# @param {string} CFLAGS - C compiler options -# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) -# @param {string} SOURCE_FILES - list of source files -# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) -# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled examples. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/examples/c/example.c b/examples/c/example.c deleted file mode 100644 index 4bc54d5..0000000 --- a/examples/c/example.c +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main( void ) { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 28811f9..0000000 --- a/examples/index.js +++ /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. -*/ - -'use strict'; - -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( './../lib' ); - -var shapes; -var out; -var sh; -var i; -var j; - -function shape2string( shape ) { - return lpad( shape.join( ' x ' ), 20, ' ' ); -} - -shapes = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] -]; - -for ( i = 0; i < shapes.length; i++ ) { - sh = shapes[ i ]; - for ( j = 0; j < sh.length; j++ ) { - console.log( shape2string( sh[ j ] ) ); - } - console.log( lpad( '', 20, '-' ) ); - - out = broadcastShapes( sh ); - console.log( shape2string( out )+'\n' ); -} diff --git a/include/stdlib/ndarray/base/broadcast_shapes.h b/include/stdlib/ndarray/base/broadcast_shapes.h deleted file mode 100644 index e23dce1..0000000 --- a/include/stdlib/ndarray/base/broadcast_shapes.h +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#ifndef STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H -#define STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H - -#include - -/* -* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. -*/ -#ifdef __cplusplus -extern "C" { -#endif - -/** -* Broadcasts array shapes to a single shape. -*/ -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H diff --git a/index.js b/index.js new file mode 100644 index 0000000..d225eb4 --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map new file mode 100644 index 0000000..0c02c0f --- /dev/null +++ b/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 0c9817e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Broadcast array shapes to a single shape. -* -* @module @stdlib/ndarray-base-broadcast-shapes -* -* @example -* var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); -* -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -*/ - -// 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 8558e60..0000000 --- a/lib/main.js +++ /dev/null @@ -1,256 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param {Array} shapes - array of shape arrays -* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`) -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [ 8, 0, 1, 6, 1 ], -* [ 8, 8, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -function broadcastShapes( shapes ) { - var ndims; - var out; - var dim; - var sh; - var n1; - var n2; - var d; - var M; - var N; - var i; - var j; - - M = shapes.length; - out = []; - if ( M === 0 ) { - return out; - } - sh = shapes[ 0 ]; - N = sh.length; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M === 1 ) { - // Need to manually copy to output shape, as shapes could be array-like objects... - for ( i = 0; i < N; i++ ) { - out.push( sh[ i ] ); - } - return out; - } - // Determine the maximum dimensionality... - ndims = [ N ]; - for ( i = 1; i < M; i++ ) { - ndims.push( shapes[ i ].length ); - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Initialize the output array... - for ( i = 0; i < N; i++ ) { - out.push( 0 ); - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim === 1 ) { - dim = d; - continue; - } - if ( d === 1 || dim === d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return null; - } - out[ i ] = dim; - i -= 1; - } - return out; -} - - -// EXPORTS // - -module.exports = broadcastShapes; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 890a937..0000000 --- a/manifest.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "options": {}, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [] - } - ] -} diff --git a/package.json b/package.json index a53e06e..0b77b65 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,7 @@ "version": "0.2.1", "description": "Broadcast array shapes to a single shape.", "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", - "include": "./include", - "lib": "./lib", - "src": "./src", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "main": "./index.js", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,33 +12,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/types": "^0.3.2", - "@stdlib/utils-library-manifest": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/string-left-pad": "^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", "stdtypes", @@ -80,9 +27,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 35a3654..0000000 --- a/src/main.c +++ /dev/null @@ -1,118 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). -* -* - Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. -* -* @param M number of array shapes -* @param shapes pointer to an array containing shape arrays -* @param ndims array containing the number of dimensions for (i.e., length of) each respective shape array -* @param out pointer to output array -* @return status -* -* @example -* #include "stdlib/ndarray/base/broadcast_shapes.h" -* #include -* -* int64_t N1 = 4; -* int64_t sh1[] = { 8, 1, 6, 1 }; -* -* int64_t N2 = 3; -* int64_t sh2[] = { 7, 1, 5 }; -* -* int64_t ndims[] = { N1, N2 }; -* int64_t *shapes[] = { sh1, sh2 }; -* -* int64_t out[] = { 0, 0, 0, 0 }; -* int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -*/ -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ) { - int64_t dim; - int64_t *sh; - int64_t n1; - int64_t n2; - int64_t d; - int64_t N; - int64_t i; - int64_t j; - - if ( M == 0 ) { - return 0; - } - sh = shapes[ 0 ]; - N = ndims[ 0 ]; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M == 1 ) { - for ( i = 0; i < N; i++ ) { - out[ i ] = sh[ i ]; - } - return 0; - } - // Determine the maximum dimensionality... - for ( i = 1; i < M; i++ ) { - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim == 1 ) { - dim = d; - continue; - } - if ( d == 1 || dim == d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return -1; - } - out[ i ] = dim; - i -= 1; - } - return 0; -} diff --git a/stats_browser.html b/stats_browser.html new file mode 100644 index 0000000..2f35700 --- /dev/null +++ b/stats_browser.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/stats_node.html b/stats_node.html new file mode 100644 index 0000000..c264c7d --- /dev/null +++ b/stats_node.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 63f703c..0000000 --- a/test/test.js +++ /dev/null @@ -1,230 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var broadcastShapes = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastShapes, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] - ]; - - expected = [ - [ 1, 2 ], - [ 3, 4 ], - [ 5, 6, 7 ], - [ 3, 3 ], - [ 3 ], - [ 3, 2 ], - [ 2, 3 ], - [ 1, 2 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty dims)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 0 ], [ 0, 0 ] ], - [ [ 0, 1 ], [ 0, 0 ] ], - [ [ 1, 0 ], [ 0, 1 ] ], - [ [ 1, 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 1, 0 ] ], - [ [ 1, 1 ], [ 0, 1 ] ], - [ [ 0 ], [ 0, 0 ] ], - [ [ 0 ], [ 0, 1 ] ], - [ [ 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 0 ] ], - [ [ 1 ], [ 0, 1 ] ], - [ [ 1 ], [ 1, 0 ] ], - [ [ 1 ], [ 8, 0 ] ], - [ [ 8, 1, 6, 1 ], [ 0, 1, 5 ] ], - [ [ 8, 0, 6, 1 ], [ 1, 5 ] ] - ]; - - expected = [ - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 1, 0 ], - [ 8, 0 ], - [ 8, 0, 6, 5 ], - [ 8, 0, 6, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (no shapes)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [] - ]; - - expected = [ - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty shapes (i.e., zero-dimensional array broadcasting))', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [] ], - [ [], [] ], - [ [], [], [] ], - [ [], [ 0 ] ], - [ [ 0 ], [] ], - [ [], [ 0, 0 ] ], - [ [ 0, 0 ], [] ], - [ [], [ 1, 0 ] ], - [ [], [ 0, 1 ] ], - [ [], [ 3, 3 ] ], - [ [], [ 3, 3 ], [] ] - ]; - - expected = [ - [], - [], - [], - [ 0 ], - [ 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 3, 3 ], - [ 3, 3 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (single shape)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 7 ] ], - [ [ 1, 1 ] ], - [ [ 5, 6, 1 ] ] - ]; - - expected = [ - [ 7 ], - [ 1, 1 ], - [ 5, 6, 1 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function returns `null` if provided incompatible shapes', function test( t ) { - var actual; - var values; - var i; - - values = [ - [ [ 3 ], [ 4 ] ], - [ [ 2, 3 ], [ 2 ] ], - [ [ 3 ], [ 3 ], [ 4 ] ], - [ [ 1, 3, 4 ], [ 2, 3, 3 ] ], - [ [ 1, 2 ], [ 3, 1 ], [ 3, 2 ], [ 10, 5 ] ], - [ [ 2 ], [ 2, 3 ] ], - [ [ 2 ], [ 2 ], [ 2 ], [ 2 ], [ 3 ], [ 3 ], [ 3 ], [ 3 ] ], - [ [ 9, 0, 9 ], [ 0, 9, 0 ] ], - [ [ 9, 9, 9 ], [ 0, 9, 9 ] ], - [ [ 9, 0, 9 ], [ 9, 9, 9 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 0 ] ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.strictEqual( actual, null, 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); From 7b026acbab73fd4694c8a6a80795180dd90860a2 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 11 Apr 2024 21:51:01 +0000 Subject: [PATCH 097/158] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index e256077..a53e06e 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,8 @@ }, "dependencies": { "@stdlib/types": "^0.3.2", - "@stdlib/utils-library-manifest": "^0.2.1" + "@stdlib/utils-library-manifest": "^0.2.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1" }, "devDependencies": { "@stdlib/string-left-pad": "^0.2.1", @@ -84,4 +85,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From dd4e60e380fe86215c74d1af56bbee6b7a10bdb6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 11 Apr 2024 23:46:52 +0000 Subject: [PATCH 098/158] Remove files --- browser.js | 3 - browser.js.map | 1 - index.js | 3 - index.js.map | 1 - stats_browser.html | 4842 -------------------------------------------- stats_node.html | 4842 -------------------------------------------- 6 files changed, 9692 deletions(-) delete mode 100644 browser.js delete mode 100644 browser.js.map delete mode 100644 index.js delete mode 100644 index.js.map delete mode 100644 stats_browser.html delete mode 100644 stats_node.html diff --git a/browser.js b/browser.js deleted file mode 100644 index 44a8074..0000000 --- a/browser.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); -//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map deleted file mode 100644 index aa4b2bb..0000000 --- a/browser.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"browser.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/index.js b/index.js deleted file mode 100644 index d225eb4..0000000 --- a/index.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); -//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map deleted file mode 100644 index 0c02c0f..0000000 --- a/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/stats_browser.html b/stats_browser.html deleted file mode 100644 index 2f35700..0000000 --- a/stats_browser.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - diff --git a/stats_node.html b/stats_node.html deleted file mode 100644 index c264c7d..0000000 --- a/stats_node.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From d36d7ff78af6a36abbb7ccd289dc11d966b0938a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 11 Apr 2024 23:47:07 +0000 Subject: [PATCH 099/158] 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 | 178 +- SECURITY.md | 5 - benchmark/benchmark.js | 112 - benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 152 - branches.md | 56 - browser.js | 3 + browser.js.map | 1 + dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 39 - docs/types/index.d.ts | 177 - docs/types/test.ts | 45 - examples/c/Makefile | 146 - examples/c/example.c | 50 - examples/index.js | 54 - .../stdlib/ndarray/base/broadcast_shapes.h | 40 - index.js | 3 + index.js.map | 1 + lib/index.js | 45 - lib/main.js | 256 - manifest.json | 38 - package.json | 58 +- src/main.c | 118 - stats_browser.html | 4842 +++++++++++++++++ stats_node.html | 4842 +++++++++++++++++ test/dist/test.js | 33 - test/test.js | 230 - 52 files changed, 9729 insertions(+), 5123 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.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 branches.md create mode 100644 browser.js create mode 100644 browser.js.map 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/index.d.ts delete mode 100644 docs/types/test.ts delete mode 100644 examples/c/Makefile delete mode 100644 examples/c/example.c delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/broadcast_shapes.h create mode 100644 index.js create mode 100644 index.js.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 manifest.json delete mode 100644 src/main.c create mode 100644 stats_browser.html create mode 100644 stats_node.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 7f004ad..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 a07d970..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 7292af0..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: '0 12 * * 5' - - # 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 +``` -```javascript -var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); +If no recognized module system is present, access bundle contents via the global scope: + +```html + ``` #### broadcastShapes( shapes ) @@ -245,9 +251,14 @@ var sh = broadcastShapes( [ sh1, sh2 ] ); -```javascript -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); +```html + + + + + + + + ```
@@ -288,131 +304,7 @@ for ( i = 0; i < shapes.length; i++ ) { -* * * - -
- -## C APIs - - - -
- -
- - - - - -
- -### Usage - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -``` - -#### stdlib_ndarray_broadcast_shapes( M, \*\*shapes, \*ndims, \*out ) - -Broadcasts array shapes to a single shape. - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -int64_t N1 = 4; -int64_t sh1[] = { 8, 1, 6, 1 }; - -int64_t N2 = 3; -int64_t sh2[] = { 7, 1, 5 }; - -int64_t ndims[] = { N1, N2 }; -int64_t *shapes[] = { sh1, sh2 }; - -int64_t out[] = { 0, 0, 0, 0 }; -int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -if ( status != 0 ) { - // Handle error... -} -``` - -The function accepts the following arguments: - -- **M**: `[in] int64_t` number of shape arrays. -- **shapes**: `[in] int64_t**` array of shape arrays (dimensions). -- **ndims**: `[in] int64_t*` number of dimensions for each respective shape array. -- **out**: `[out] int64_t*` output shape array. - -```c -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ); -``` - -If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). - -
- - - - - -
- -### Notes - -- Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. - -
- - - - - -
- -### Examples - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main( void ) { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} -``` - -
- - - -
- 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.js b/benchmark/benchmark.js deleted file mode 100644 index 6426216..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,112 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pkg = require( './../package.json' ).name; -var broadcastShapes = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::two_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ] ], - [ [ 3, 2 ], [ 3, 1 ] ], - [ [ 1, 1 ], [ 2, 2 ] ], - [ [ 1 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::three_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::four_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ], [ 8, 1, 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ], [ 1, 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ], [ 1, 1, 2, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ], [ 1 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ], [ 5, 1, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/c/Makefile b/benchmark/c/Makefile deleted file mode 100644 index 5dc545c..0000000 --- a/benchmark/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := benchmark.out - - -# RULES # - -#/ -# Compiles C source files. -# -# @param {string} SOURCE_FILES - list of C source files -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lpthread -lblas`) -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [C_COMPILER] - C compiler -# @param {string} [CFLAGS] - C compiler flags -# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} SOURCE_FILES - list of C source files -# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {(string|void)} LIBRARIES - list of libraries (e.g., `-lpthread -lblas`) -# @param {(string|void)} LIBPATH - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} CC - C compiler -# @param {string} CFLAGS - C compiler flags -# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled benchmarks. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/benchmark/c/benchmark.c b/benchmark/c/benchmark.c deleted file mode 100644 index be62cd5..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,152 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/** -* Benchmark `broadcast_shapes`. -*/ -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "broadcast-shapes" -#define ITERATIONS 1000000 -#define REPEATS 3 - -/** -* Prints the TAP version. -*/ -void print_version() { - printf( "TAP version 13\n" ); -} - -/** -* Prints the TAP summary. -* -* @param total total number of tests -* @param passing total number of passing tests -*/ -void print_summary( int total, int passing ) { - printf( "#\n" ); - printf( "1..%d\n", total ); // TAP plan - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); -} - -/** -* Prints benchmarks results. -* -* @param elapsed elapsed time in seconds -*/ -void print_results( double elapsed ) { - double rate = (double)ITERATIONS / elapsed; - printf( " ---\n" ); - printf( " iterations: %d\n", ITERATIONS ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", rate ); - printf( " ...\n" ); -} - -/** -* Returns a clock time. -* -* @return clock time -*/ -double tic() { - struct timeval now; - gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; -} - -/** -* Generates a random double on the interval [0,1]. -* -* @return random double -*/ -double rand_double() { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark() { - double elapsed; - int8_t status; - double t; - int i; - - int64_t sh1[] = { 8, 1, 6, 1 }; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { 4, 3 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( out[ 0 ] != 8 ) { - printf( "unexpected result\n" ); - } - if ( out[ 1 ] != 7 ) { - printf( "unexpected result\n" ); - } - if ( out[ 2 ] != 6 ) { - printf( "unexpected result\n" ); - } - if ( out[ 3 ] != 5 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Main execution sequence. -*/ -int main( void ) { - double elapsed; - int i; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - for ( i = 0; i < REPEATS; i++ ) { - printf( "# c::native::%s::two_arrays\n", NAME ); - elapsed = benchmark(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", i+1 ); - } - print_summary( REPEATS, REPEATS ); -} diff --git a/branches.md b/branches.md deleted file mode 100644 index 79909c9..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes" -%% click B href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/blob/esm/README.md \ No newline at end of file diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..44a8074 --- /dev/null +++ b/browser.js @@ -0,0 +1,3 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map new file mode 100644 index 0000000..aa4b2bb --- /dev/null +++ b/browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"browser.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 87ea8b6..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import broadcastShapes from '../docs/types/index'; -export = broadcastShapes; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 625741a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var d=function(t,e){return function(){return e||t((e={exports:{}}).exports,e),e.exports}};var h=d(function(x,c){ -function g(t){var e,n,u,o,s,l,a,f,i,r,v;if(f=t.length,n=[],f===0)return n;if(o=t[0],i=o.length,f===1){for(r=0;ri&&(i=e[r]);for(r=0;r=0;){for(s=e[0]-i+r,s>=0?u=o[s]:u=1,v=1;v=0?a=t[v][l]:a=1,u===1){u=a;continue}if(!(a===1||u===a))return null}n[r]=u,r-=1}return n}c.exports=g -});var m=h();module.exports=m; -/** @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 db2949f..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = broadcastShapes;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast array shapes to a single shape.\n*\n* @module @stdlib/ndarray-base-broadcast-shapes\n*\n* @example\n* var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' );\n*\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\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,cAkLA,SAASC,EAAiBC,EAAS,CAClC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GAFAH,EAAIR,EAAO,OACXE,EAAM,CAAC,EACFM,IAAM,EACV,OAAON,EAMR,GAJAE,EAAKJ,EAAQ,CAAE,EACfS,EAAIL,EAAG,OAGFI,IAAM,EAAI,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAI,KAAME,EAAIM,CAAE,CAAE,EAEnB,OAAOR,CACR,CAGA,IADAD,EAAQ,CAAEQ,CAAE,EACNC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAM,KAAMD,EAAQU,CAAE,EAAE,MAAO,EAC1BT,EAAOS,CAAE,EAAID,IACjBA,EAAIR,EAAOS,CAAE,GAIf,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAI,KAAM,CAAE,EAIb,IADAQ,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IANAL,EAAKJ,EAAO,CAAE,EAAIQ,EAAIC,EACjBL,GAAM,EACVF,EAAMC,EAAIC,CAAG,EAEbF,EAAM,EAEDQ,EAAI,EAAGA,EAAIH,EAAGG,IAAM,CAOzB,GANAL,EAAKL,EAAOU,CAAE,EAAIF,EAAIC,EACjBJ,GAAM,EACVC,EAAIP,EAAQW,CAAE,EAAGL,CAAG,EAEpBC,EAAI,EAEAJ,IAAQ,EAAI,CAChBA,EAAMI,EACN,QACD,CACA,GAAK,EAAAA,IAAM,GAAKJ,IAAQI,GAKxB,OAAO,IACR,CACAL,EAAKQ,CAAE,EAAIP,EACXO,GAAK,CACN,CACA,OAAOR,CACR,CAKAJ,EAAO,QAAUC,ICxNjB,IAAIa,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "broadcastShapes", "shapes", "ndims", "out", "dim", "sh", "n1", "n2", "d", "M", "N", "i", "j", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f1d92f6..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,39 +0,0 @@ - -{{alias}}( shapes ) - Broadcasts array shapes to a single shape. - - Two respective dimensions in two shape arrays are compatible if - - 1. the dimensions are equal. - 2. one dimension is `1`. - - The function returns `null` if provided incompatible shapes (i.e., shapes - which cannot be broadcast with one another). - - Parameters - ---------- - shapes: Array - Array of shape arrays. - - Returns - ------- - out: Array|null - Broadcast shape. - - Examples - -------- - // Compatible shapes: - > var sh1 = [ 8, 1, 6, 1 ]; - > var sh2 = [ 7, 1, 5 ]; - > var sh = {{alias}}( [ sh1, sh2 ] ) - [ 8, 7, 6, 5 ] - - // Incompatible shapes: - > sh1 = [ 3, 2 ]; - > sh1 = [ 2, 3 ]; - > sh = {{alias}}( [ sh1, sh2 ] ) - null - - See Also - -------- - diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts deleted file mode 100644 index c2702cf..0000000 --- a/docs/types/index.d.ts +++ /dev/null @@ -1,177 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ArrayLike } from '@stdlib/types/array'; - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param shapes - array shapes -* @returns broadcast shape -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -declare function broadcastShapes( shapes: ArrayLike> ): ArrayLike; - - -// EXPORTS // - -export = broadcastShapes; diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 2886539..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 broadcastShapes = require( './index' ); - - -// TESTS // - -// The function returns an array of numbers... -{ - broadcastShapes( [ [ 1, 2 ], [ 2, 2 ] ] ); // $ExpectType ArrayLike -} - -// The compiler throws an error if the function is not provided an array-like object containing array-like objects containing numbers... -{ - broadcastShapes( '5' ); // $ExpectError - broadcastShapes( 5 ); // $ExpectError - broadcastShapes( true ); // $ExpectError - broadcastShapes( false ); // $ExpectError - broadcastShapes( null ); // $ExpectError - broadcastShapes( {} ); // $ExpectError - broadcastShapes( [ '5' ] ); // $ExpectError - broadcastShapes( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - broadcastShapes(); // $ExpectError - broadcastShapes( [ [ 1, 2, 3 ] ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/c/Makefile b/examples/c/Makefile deleted file mode 100644 index 70c91f4..0000000 --- a/examples/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := example.out - - -# RULES # - -#/ -# Compiles source files. -# -# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) -# @param {string} [CFLAGS] - C compiler options -# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) -# @param {string} [SOURCE_FILES] - list of source files -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} CC - C compiler (e.g., `gcc`) -# @param {string} CFLAGS - C compiler options -# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) -# @param {string} SOURCE_FILES - list of source files -# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) -# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled examples. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/examples/c/example.c b/examples/c/example.c deleted file mode 100644 index 4bc54d5..0000000 --- a/examples/c/example.c +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main( void ) { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 28811f9..0000000 --- a/examples/index.js +++ /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. -*/ - -'use strict'; - -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( './../lib' ); - -var shapes; -var out; -var sh; -var i; -var j; - -function shape2string( shape ) { - return lpad( shape.join( ' x ' ), 20, ' ' ); -} - -shapes = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] -]; - -for ( i = 0; i < shapes.length; i++ ) { - sh = shapes[ i ]; - for ( j = 0; j < sh.length; j++ ) { - console.log( shape2string( sh[ j ] ) ); - } - console.log( lpad( '', 20, '-' ) ); - - out = broadcastShapes( sh ); - console.log( shape2string( out )+'\n' ); -} diff --git a/include/stdlib/ndarray/base/broadcast_shapes.h b/include/stdlib/ndarray/base/broadcast_shapes.h deleted file mode 100644 index e23dce1..0000000 --- a/include/stdlib/ndarray/base/broadcast_shapes.h +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#ifndef STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H -#define STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H - -#include - -/* -* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. -*/ -#ifdef __cplusplus -extern "C" { -#endif - -/** -* Broadcasts array shapes to a single shape. -*/ -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H diff --git a/index.js b/index.js new file mode 100644 index 0000000..d225eb4 --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map new file mode 100644 index 0000000..0c02c0f --- /dev/null +++ b/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 0c9817e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Broadcast array shapes to a single shape. -* -* @module @stdlib/ndarray-base-broadcast-shapes -* -* @example -* var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); -* -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -*/ - -// 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 8558e60..0000000 --- a/lib/main.js +++ /dev/null @@ -1,256 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param {Array} shapes - array of shape arrays -* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`) -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [ 8, 0, 1, 6, 1 ], -* [ 8, 8, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -function broadcastShapes( shapes ) { - var ndims; - var out; - var dim; - var sh; - var n1; - var n2; - var d; - var M; - var N; - var i; - var j; - - M = shapes.length; - out = []; - if ( M === 0 ) { - return out; - } - sh = shapes[ 0 ]; - N = sh.length; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M === 1 ) { - // Need to manually copy to output shape, as shapes could be array-like objects... - for ( i = 0; i < N; i++ ) { - out.push( sh[ i ] ); - } - return out; - } - // Determine the maximum dimensionality... - ndims = [ N ]; - for ( i = 1; i < M; i++ ) { - ndims.push( shapes[ i ].length ); - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Initialize the output array... - for ( i = 0; i < N; i++ ) { - out.push( 0 ); - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim === 1 ) { - dim = d; - continue; - } - if ( d === 1 || dim === d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return null; - } - out[ i ] = dim; - i -= 1; - } - return out; -} - - -// EXPORTS // - -module.exports = broadcastShapes; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 890a937..0000000 --- a/manifest.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "options": {}, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [] - } - ] -} diff --git a/package.json b/package.json index a53e06e..0b77b65 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,7 @@ "version": "0.2.1", "description": "Broadcast array shapes to a single shape.", "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", - "include": "./include", - "lib": "./lib", - "src": "./src", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "main": "./index.js", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,33 +12,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/types": "^0.3.2", - "@stdlib/utils-library-manifest": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/string-left-pad": "^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", "stdtypes", @@ -80,9 +27,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 35a3654..0000000 --- a/src/main.c +++ /dev/null @@ -1,118 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). -* -* - Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. -* -* @param M number of array shapes -* @param shapes pointer to an array containing shape arrays -* @param ndims array containing the number of dimensions for (i.e., length of) each respective shape array -* @param out pointer to output array -* @return status -* -* @example -* #include "stdlib/ndarray/base/broadcast_shapes.h" -* #include -* -* int64_t N1 = 4; -* int64_t sh1[] = { 8, 1, 6, 1 }; -* -* int64_t N2 = 3; -* int64_t sh2[] = { 7, 1, 5 }; -* -* int64_t ndims[] = { N1, N2 }; -* int64_t *shapes[] = { sh1, sh2 }; -* -* int64_t out[] = { 0, 0, 0, 0 }; -* int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -*/ -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ) { - int64_t dim; - int64_t *sh; - int64_t n1; - int64_t n2; - int64_t d; - int64_t N; - int64_t i; - int64_t j; - - if ( M == 0 ) { - return 0; - } - sh = shapes[ 0 ]; - N = ndims[ 0 ]; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M == 1 ) { - for ( i = 0; i < N; i++ ) { - out[ i ] = sh[ i ]; - } - return 0; - } - // Determine the maximum dimensionality... - for ( i = 1; i < M; i++ ) { - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim == 1 ) { - dim = d; - continue; - } - if ( d == 1 || dim == d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return -1; - } - out[ i ] = dim; - i -= 1; - } - return 0; -} diff --git a/stats_browser.html b/stats_browser.html new file mode 100644 index 0000000..2f35700 --- /dev/null +++ b/stats_browser.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/stats_node.html b/stats_node.html new file mode 100644 index 0000000..c264c7d --- /dev/null +++ b/stats_node.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 63f703c..0000000 --- a/test/test.js +++ /dev/null @@ -1,230 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var broadcastShapes = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastShapes, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] - ]; - - expected = [ - [ 1, 2 ], - [ 3, 4 ], - [ 5, 6, 7 ], - [ 3, 3 ], - [ 3 ], - [ 3, 2 ], - [ 2, 3 ], - [ 1, 2 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty dims)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 0 ], [ 0, 0 ] ], - [ [ 0, 1 ], [ 0, 0 ] ], - [ [ 1, 0 ], [ 0, 1 ] ], - [ [ 1, 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 1, 0 ] ], - [ [ 1, 1 ], [ 0, 1 ] ], - [ [ 0 ], [ 0, 0 ] ], - [ [ 0 ], [ 0, 1 ] ], - [ [ 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 0 ] ], - [ [ 1 ], [ 0, 1 ] ], - [ [ 1 ], [ 1, 0 ] ], - [ [ 1 ], [ 8, 0 ] ], - [ [ 8, 1, 6, 1 ], [ 0, 1, 5 ] ], - [ [ 8, 0, 6, 1 ], [ 1, 5 ] ] - ]; - - expected = [ - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 1, 0 ], - [ 8, 0 ], - [ 8, 0, 6, 5 ], - [ 8, 0, 6, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (no shapes)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [] - ]; - - expected = [ - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty shapes (i.e., zero-dimensional array broadcasting))', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [] ], - [ [], [] ], - [ [], [], [] ], - [ [], [ 0 ] ], - [ [ 0 ], [] ], - [ [], [ 0, 0 ] ], - [ [ 0, 0 ], [] ], - [ [], [ 1, 0 ] ], - [ [], [ 0, 1 ] ], - [ [], [ 3, 3 ] ], - [ [], [ 3, 3 ], [] ] - ]; - - expected = [ - [], - [], - [], - [ 0 ], - [ 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 3, 3 ], - [ 3, 3 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (single shape)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 7 ] ], - [ [ 1, 1 ] ], - [ [ 5, 6, 1 ] ] - ]; - - expected = [ - [ 7 ], - [ 1, 1 ], - [ 5, 6, 1 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function returns `null` if provided incompatible shapes', function test( t ) { - var actual; - var values; - var i; - - values = [ - [ [ 3 ], [ 4 ] ], - [ [ 2, 3 ], [ 2 ] ], - [ [ 3 ], [ 3 ], [ 4 ] ], - [ [ 1, 3, 4 ], [ 2, 3, 3 ] ], - [ [ 1, 2 ], [ 3, 1 ], [ 3, 2 ], [ 10, 5 ] ], - [ [ 2 ], [ 2, 3 ] ], - [ [ 2 ], [ 2 ], [ 2 ], [ 2 ], [ 3 ], [ 3 ], [ 3 ], [ 3 ] ], - [ [ 9, 0, 9 ], [ 0, 9, 0 ] ], - [ [ 9, 9, 9 ], [ 0, 9, 9 ] ], - [ [ 9, 0, 9 ], [ 9, 9, 9 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 0 ] ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.strictEqual( actual, null, 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); From 3e2c3a59c15af4c2ee97bf9e8a1e8acab2e53fb1 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 May 2024 01:45:39 +0000 Subject: [PATCH 100/158] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index e256077..a53e06e 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,8 @@ }, "dependencies": { "@stdlib/types": "^0.3.2", - "@stdlib/utils-library-manifest": "^0.2.1" + "@stdlib/utils-library-manifest": "^0.2.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1" }, "devDependencies": { "@stdlib/string-left-pad": "^0.2.1", @@ -84,4 +85,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From 7cb43372005a6052da592f86d6fd5d2f2ff1f205 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 May 2024 03:17:20 +0000 Subject: [PATCH 101/158] Remove files --- browser.js | 3 - browser.js.map | 1 - index.js | 3 - index.js.map | 1 - stats_browser.html | 4842 -------------------------------------------- stats_node.html | 4842 -------------------------------------------- 6 files changed, 9692 deletions(-) delete mode 100644 browser.js delete mode 100644 browser.js.map delete mode 100644 index.js delete mode 100644 index.js.map delete mode 100644 stats_browser.html delete mode 100644 stats_node.html diff --git a/browser.js b/browser.js deleted file mode 100644 index 44a8074..0000000 --- a/browser.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); -//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map deleted file mode 100644 index aa4b2bb..0000000 --- a/browser.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"browser.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/index.js b/index.js deleted file mode 100644 index d225eb4..0000000 --- a/index.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); -//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map deleted file mode 100644 index 0c02c0f..0000000 --- a/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/stats_browser.html b/stats_browser.html deleted file mode 100644 index 2f35700..0000000 --- a/stats_browser.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - diff --git a/stats_node.html b/stats_node.html deleted file mode 100644 index c264c7d..0000000 --- a/stats_node.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From f2fc9d96d84e395350d967a54d75bb44bb9261a1 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 May 2024 03:17:38 +0000 Subject: [PATCH 102/158] 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 | 248 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .gitignore | 188 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 178 +- SECURITY.md | 5 - benchmark/benchmark.js | 112 - benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 152 - branches.md | 56 - browser.js | 3 + browser.js.map | 1 + dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 39 - docs/types/index.d.ts | 177 - docs/types/test.ts | 45 - examples/c/Makefile | 146 - examples/c/example.c | 50 - examples/index.js | 54 - .../stdlib/ndarray/base/broadcast_shapes.h | 40 - index.js | 3 + index.js.map | 1 + lib/index.js | 45 - lib/main.js | 256 - manifest.json | 38 - package.json | 58 +- src/main.c | 118 - stats_browser.html | 4842 +++++++++++++++++ stats_node.html | 4842 +++++++++++++++++ test/dist/test.js | 33 - test/test.js | 230 - 53 files changed, 9729 insertions(+), 5131 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.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 branches.md create mode 100644 browser.js create mode 100644 browser.js.map 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/index.d.ts delete mode 100644 docs/types/test.ts delete mode 100644 examples/c/Makefile delete mode 100644 examples/c/example.c delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/broadcast_shapes.h create mode 100644 index.js create mode 100644 index.js.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 manifest.json delete mode 100644 src/main.c create mode 100644 stats_browser.html create mode 100644 stats_node.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/.keepalive b/.github/.keepalive deleted file mode 100644 index 3dae215..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-05-01T01:16:47.304Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 7f004ad..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 a07d970..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 7292af0..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: '0 12 * * 5' - - # 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 +``` -```javascript -var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); +If no recognized module system is present, access bundle contents via the global scope: + +```html + ``` #### broadcastShapes( shapes ) @@ -245,9 +251,14 @@ var sh = broadcastShapes( [ sh1, sh2 ] ); -```javascript -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); +```html + + + + + + + + ```
@@ -288,131 +304,7 @@ for ( i = 0; i < shapes.length; i++ ) { -* * * - -
- -## C APIs - - - -
- -
- - - - - -
- -### Usage - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -``` - -#### stdlib_ndarray_broadcast_shapes( M, \*\*shapes, \*ndims, \*out ) - -Broadcasts array shapes to a single shape. - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -int64_t N1 = 4; -int64_t sh1[] = { 8, 1, 6, 1 }; - -int64_t N2 = 3; -int64_t sh2[] = { 7, 1, 5 }; - -int64_t ndims[] = { N1, N2 }; -int64_t *shapes[] = { sh1, sh2 }; - -int64_t out[] = { 0, 0, 0, 0 }; -int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -if ( status != 0 ) { - // Handle error... -} -``` - -The function accepts the following arguments: - -- **M**: `[in] int64_t` number of shape arrays. -- **shapes**: `[in] int64_t**` array of shape arrays (dimensions). -- **ndims**: `[in] int64_t*` number of dimensions for each respective shape array. -- **out**: `[out] int64_t*` output shape array. - -```c -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ); -``` - -If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). - -
- - - - - -
- -### Notes - -- Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. - -
- - - - - -
- -### Examples - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main( void ) { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} -``` - -
- - - -
- 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.js b/benchmark/benchmark.js deleted file mode 100644 index 6426216..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,112 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pkg = require( './../package.json' ).name; -var broadcastShapes = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::two_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ] ], - [ [ 3, 2 ], [ 3, 1 ] ], - [ [ 1, 1 ], [ 2, 2 ] ], - [ [ 1 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::three_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::four_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ], [ 8, 1, 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ], [ 1, 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ], [ 1, 1, 2, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ], [ 1 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ], [ 5, 1, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/c/Makefile b/benchmark/c/Makefile deleted file mode 100644 index 5dc545c..0000000 --- a/benchmark/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := benchmark.out - - -# RULES # - -#/ -# Compiles C source files. -# -# @param {string} SOURCE_FILES - list of C source files -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lpthread -lblas`) -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [C_COMPILER] - C compiler -# @param {string} [CFLAGS] - C compiler flags -# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} SOURCE_FILES - list of C source files -# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {(string|void)} LIBRARIES - list of libraries (e.g., `-lpthread -lblas`) -# @param {(string|void)} LIBPATH - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} CC - C compiler -# @param {string} CFLAGS - C compiler flags -# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled benchmarks. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/benchmark/c/benchmark.c b/benchmark/c/benchmark.c deleted file mode 100644 index be62cd5..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,152 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/** -* Benchmark `broadcast_shapes`. -*/ -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "broadcast-shapes" -#define ITERATIONS 1000000 -#define REPEATS 3 - -/** -* Prints the TAP version. -*/ -void print_version() { - printf( "TAP version 13\n" ); -} - -/** -* Prints the TAP summary. -* -* @param total total number of tests -* @param passing total number of passing tests -*/ -void print_summary( int total, int passing ) { - printf( "#\n" ); - printf( "1..%d\n", total ); // TAP plan - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); -} - -/** -* Prints benchmarks results. -* -* @param elapsed elapsed time in seconds -*/ -void print_results( double elapsed ) { - double rate = (double)ITERATIONS / elapsed; - printf( " ---\n" ); - printf( " iterations: %d\n", ITERATIONS ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", rate ); - printf( " ...\n" ); -} - -/** -* Returns a clock time. -* -* @return clock time -*/ -double tic() { - struct timeval now; - gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; -} - -/** -* Generates a random double on the interval [0,1]. -* -* @return random double -*/ -double rand_double() { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark() { - double elapsed; - int8_t status; - double t; - int i; - - int64_t sh1[] = { 8, 1, 6, 1 }; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { 4, 3 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( out[ 0 ] != 8 ) { - printf( "unexpected result\n" ); - } - if ( out[ 1 ] != 7 ) { - printf( "unexpected result\n" ); - } - if ( out[ 2 ] != 6 ) { - printf( "unexpected result\n" ); - } - if ( out[ 3 ] != 5 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Main execution sequence. -*/ -int main( void ) { - double elapsed; - int i; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - for ( i = 0; i < REPEATS; i++ ) { - printf( "# c::native::%s::two_arrays\n", NAME ); - elapsed = benchmark(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", i+1 ); - } - print_summary( REPEATS, REPEATS ); -} diff --git a/branches.md b/branches.md deleted file mode 100644 index 79909c9..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes" -%% click B href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/blob/esm/README.md \ No newline at end of file diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..44a8074 --- /dev/null +++ b/browser.js @@ -0,0 +1,3 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map new file mode 100644 index 0000000..aa4b2bb --- /dev/null +++ b/browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"browser.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 87ea8b6..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import broadcastShapes from '../docs/types/index'; -export = broadcastShapes; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 625741a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var d=function(t,e){return function(){return e||t((e={exports:{}}).exports,e),e.exports}};var h=d(function(x,c){ -function g(t){var e,n,u,o,s,l,a,f,i,r,v;if(f=t.length,n=[],f===0)return n;if(o=t[0],i=o.length,f===1){for(r=0;ri&&(i=e[r]);for(r=0;r=0;){for(s=e[0]-i+r,s>=0?u=o[s]:u=1,v=1;v=0?a=t[v][l]:a=1,u===1){u=a;continue}if(!(a===1||u===a))return null}n[r]=u,r-=1}return n}c.exports=g -});var m=h();module.exports=m; -/** @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 db2949f..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = broadcastShapes;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast array shapes to a single shape.\n*\n* @module @stdlib/ndarray-base-broadcast-shapes\n*\n* @example\n* var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' );\n*\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\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,cAkLA,SAASC,EAAiBC,EAAS,CAClC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GAFAH,EAAIR,EAAO,OACXE,EAAM,CAAC,EACFM,IAAM,EACV,OAAON,EAMR,GAJAE,EAAKJ,EAAQ,CAAE,EACfS,EAAIL,EAAG,OAGFI,IAAM,EAAI,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAI,KAAME,EAAIM,CAAE,CAAE,EAEnB,OAAOR,CACR,CAGA,IADAD,EAAQ,CAAEQ,CAAE,EACNC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAM,KAAMD,EAAQU,CAAE,EAAE,MAAO,EAC1BT,EAAOS,CAAE,EAAID,IACjBA,EAAIR,EAAOS,CAAE,GAIf,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAI,KAAM,CAAE,EAIb,IADAQ,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IANAL,EAAKJ,EAAO,CAAE,EAAIQ,EAAIC,EACjBL,GAAM,EACVF,EAAMC,EAAIC,CAAG,EAEbF,EAAM,EAEDQ,EAAI,EAAGA,EAAIH,EAAGG,IAAM,CAOzB,GANAL,EAAKL,EAAOU,CAAE,EAAIF,EAAIC,EACjBJ,GAAM,EACVC,EAAIP,EAAQW,CAAE,EAAGL,CAAG,EAEpBC,EAAI,EAEAJ,IAAQ,EAAI,CAChBA,EAAMI,EACN,QACD,CACA,GAAK,EAAAA,IAAM,GAAKJ,IAAQI,GAKxB,OAAO,IACR,CACAL,EAAKQ,CAAE,EAAIP,EACXO,GAAK,CACN,CACA,OAAOR,CACR,CAKAJ,EAAO,QAAUC,ICxNjB,IAAIa,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "broadcastShapes", "shapes", "ndims", "out", "dim", "sh", "n1", "n2", "d", "M", "N", "i", "j", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f1d92f6..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,39 +0,0 @@ - -{{alias}}( shapes ) - Broadcasts array shapes to a single shape. - - Two respective dimensions in two shape arrays are compatible if - - 1. the dimensions are equal. - 2. one dimension is `1`. - - The function returns `null` if provided incompatible shapes (i.e., shapes - which cannot be broadcast with one another). - - Parameters - ---------- - shapes: Array - Array of shape arrays. - - Returns - ------- - out: Array|null - Broadcast shape. - - Examples - -------- - // Compatible shapes: - > var sh1 = [ 8, 1, 6, 1 ]; - > var sh2 = [ 7, 1, 5 ]; - > var sh = {{alias}}( [ sh1, sh2 ] ) - [ 8, 7, 6, 5 ] - - // Incompatible shapes: - > sh1 = [ 3, 2 ]; - > sh1 = [ 2, 3 ]; - > sh = {{alias}}( [ sh1, sh2 ] ) - null - - See Also - -------- - diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts deleted file mode 100644 index c2702cf..0000000 --- a/docs/types/index.d.ts +++ /dev/null @@ -1,177 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ArrayLike } from '@stdlib/types/array'; - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param shapes - array shapes -* @returns broadcast shape -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -declare function broadcastShapes( shapes: ArrayLike> ): ArrayLike; - - -// EXPORTS // - -export = broadcastShapes; diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 2886539..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 broadcastShapes = require( './index' ); - - -// TESTS // - -// The function returns an array of numbers... -{ - broadcastShapes( [ [ 1, 2 ], [ 2, 2 ] ] ); // $ExpectType ArrayLike -} - -// The compiler throws an error if the function is not provided an array-like object containing array-like objects containing numbers... -{ - broadcastShapes( '5' ); // $ExpectError - broadcastShapes( 5 ); // $ExpectError - broadcastShapes( true ); // $ExpectError - broadcastShapes( false ); // $ExpectError - broadcastShapes( null ); // $ExpectError - broadcastShapes( {} ); // $ExpectError - broadcastShapes( [ '5' ] ); // $ExpectError - broadcastShapes( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - broadcastShapes(); // $ExpectError - broadcastShapes( [ [ 1, 2, 3 ] ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/c/Makefile b/examples/c/Makefile deleted file mode 100644 index 70c91f4..0000000 --- a/examples/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := example.out - - -# RULES # - -#/ -# Compiles source files. -# -# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) -# @param {string} [CFLAGS] - C compiler options -# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) -# @param {string} [SOURCE_FILES] - list of source files -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} CC - C compiler (e.g., `gcc`) -# @param {string} CFLAGS - C compiler options -# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) -# @param {string} SOURCE_FILES - list of source files -# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) -# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled examples. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/examples/c/example.c b/examples/c/example.c deleted file mode 100644 index 4bc54d5..0000000 --- a/examples/c/example.c +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main( void ) { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 28811f9..0000000 --- a/examples/index.js +++ /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. -*/ - -'use strict'; - -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( './../lib' ); - -var shapes; -var out; -var sh; -var i; -var j; - -function shape2string( shape ) { - return lpad( shape.join( ' x ' ), 20, ' ' ); -} - -shapes = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] -]; - -for ( i = 0; i < shapes.length; i++ ) { - sh = shapes[ i ]; - for ( j = 0; j < sh.length; j++ ) { - console.log( shape2string( sh[ j ] ) ); - } - console.log( lpad( '', 20, '-' ) ); - - out = broadcastShapes( sh ); - console.log( shape2string( out )+'\n' ); -} diff --git a/include/stdlib/ndarray/base/broadcast_shapes.h b/include/stdlib/ndarray/base/broadcast_shapes.h deleted file mode 100644 index e23dce1..0000000 --- a/include/stdlib/ndarray/base/broadcast_shapes.h +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#ifndef STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H -#define STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H - -#include - -/* -* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. -*/ -#ifdef __cplusplus -extern "C" { -#endif - -/** -* Broadcasts array shapes to a single shape. -*/ -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H diff --git a/index.js b/index.js new file mode 100644 index 0000000..d225eb4 --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map new file mode 100644 index 0000000..0c02c0f --- /dev/null +++ b/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 0c9817e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Broadcast array shapes to a single shape. -* -* @module @stdlib/ndarray-base-broadcast-shapes -* -* @example -* var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); -* -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -*/ - -// 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 8558e60..0000000 --- a/lib/main.js +++ /dev/null @@ -1,256 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param {Array} shapes - array of shape arrays -* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`) -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [ 8, 0, 1, 6, 1 ], -* [ 8, 8, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -function broadcastShapes( shapes ) { - var ndims; - var out; - var dim; - var sh; - var n1; - var n2; - var d; - var M; - var N; - var i; - var j; - - M = shapes.length; - out = []; - if ( M === 0 ) { - return out; - } - sh = shapes[ 0 ]; - N = sh.length; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M === 1 ) { - // Need to manually copy to output shape, as shapes could be array-like objects... - for ( i = 0; i < N; i++ ) { - out.push( sh[ i ] ); - } - return out; - } - // Determine the maximum dimensionality... - ndims = [ N ]; - for ( i = 1; i < M; i++ ) { - ndims.push( shapes[ i ].length ); - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Initialize the output array... - for ( i = 0; i < N; i++ ) { - out.push( 0 ); - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim === 1 ) { - dim = d; - continue; - } - if ( d === 1 || dim === d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return null; - } - out[ i ] = dim; - i -= 1; - } - return out; -} - - -// EXPORTS // - -module.exports = broadcastShapes; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 890a937..0000000 --- a/manifest.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "options": {}, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [] - } - ] -} diff --git a/package.json b/package.json index a53e06e..0b77b65 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,7 @@ "version": "0.2.1", "description": "Broadcast array shapes to a single shape.", "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", - "include": "./include", - "lib": "./lib", - "src": "./src", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "main": "./index.js", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,33 +12,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/types": "^0.3.2", - "@stdlib/utils-library-manifest": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/string-left-pad": "^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", "stdtypes", @@ -80,9 +27,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 35a3654..0000000 --- a/src/main.c +++ /dev/null @@ -1,118 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). -* -* - Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. -* -* @param M number of array shapes -* @param shapes pointer to an array containing shape arrays -* @param ndims array containing the number of dimensions for (i.e., length of) each respective shape array -* @param out pointer to output array -* @return status -* -* @example -* #include "stdlib/ndarray/base/broadcast_shapes.h" -* #include -* -* int64_t N1 = 4; -* int64_t sh1[] = { 8, 1, 6, 1 }; -* -* int64_t N2 = 3; -* int64_t sh2[] = { 7, 1, 5 }; -* -* int64_t ndims[] = { N1, N2 }; -* int64_t *shapes[] = { sh1, sh2 }; -* -* int64_t out[] = { 0, 0, 0, 0 }; -* int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -*/ -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ) { - int64_t dim; - int64_t *sh; - int64_t n1; - int64_t n2; - int64_t d; - int64_t N; - int64_t i; - int64_t j; - - if ( M == 0 ) { - return 0; - } - sh = shapes[ 0 ]; - N = ndims[ 0 ]; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M == 1 ) { - for ( i = 0; i < N; i++ ) { - out[ i ] = sh[ i ]; - } - return 0; - } - // Determine the maximum dimensionality... - for ( i = 1; i < M; i++ ) { - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim == 1 ) { - dim = d; - continue; - } - if ( d == 1 || dim == d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return -1; - } - out[ i ] = dim; - i -= 1; - } - return 0; -} diff --git a/stats_browser.html b/stats_browser.html new file mode 100644 index 0000000..2f35700 --- /dev/null +++ b/stats_browser.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/stats_node.html b/stats_node.html new file mode 100644 index 0000000..c264c7d --- /dev/null +++ b/stats_node.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 63f703c..0000000 --- a/test/test.js +++ /dev/null @@ -1,230 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var broadcastShapes = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastShapes, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] - ]; - - expected = [ - [ 1, 2 ], - [ 3, 4 ], - [ 5, 6, 7 ], - [ 3, 3 ], - [ 3 ], - [ 3, 2 ], - [ 2, 3 ], - [ 1, 2 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty dims)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 0 ], [ 0, 0 ] ], - [ [ 0, 1 ], [ 0, 0 ] ], - [ [ 1, 0 ], [ 0, 1 ] ], - [ [ 1, 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 1, 0 ] ], - [ [ 1, 1 ], [ 0, 1 ] ], - [ [ 0 ], [ 0, 0 ] ], - [ [ 0 ], [ 0, 1 ] ], - [ [ 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 0 ] ], - [ [ 1 ], [ 0, 1 ] ], - [ [ 1 ], [ 1, 0 ] ], - [ [ 1 ], [ 8, 0 ] ], - [ [ 8, 1, 6, 1 ], [ 0, 1, 5 ] ], - [ [ 8, 0, 6, 1 ], [ 1, 5 ] ] - ]; - - expected = [ - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 1, 0 ], - [ 8, 0 ], - [ 8, 0, 6, 5 ], - [ 8, 0, 6, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (no shapes)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [] - ]; - - expected = [ - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty shapes (i.e., zero-dimensional array broadcasting))', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [] ], - [ [], [] ], - [ [], [], [] ], - [ [], [ 0 ] ], - [ [ 0 ], [] ], - [ [], [ 0, 0 ] ], - [ [ 0, 0 ], [] ], - [ [], [ 1, 0 ] ], - [ [], [ 0, 1 ] ], - [ [], [ 3, 3 ] ], - [ [], [ 3, 3 ], [] ] - ]; - - expected = [ - [], - [], - [], - [ 0 ], - [ 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 3, 3 ], - [ 3, 3 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (single shape)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 7 ] ], - [ [ 1, 1 ] ], - [ [ 5, 6, 1 ] ] - ]; - - expected = [ - [ 7 ], - [ 1, 1 ], - [ 5, 6, 1 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function returns `null` if provided incompatible shapes', function test( t ) { - var actual; - var values; - var i; - - values = [ - [ [ 3 ], [ 4 ] ], - [ [ 2, 3 ], [ 2 ] ], - [ [ 3 ], [ 3 ], [ 4 ] ], - [ [ 1, 3, 4 ], [ 2, 3, 3 ] ], - [ [ 1, 2 ], [ 3, 1 ], [ 3, 2 ], [ 10, 5 ] ], - [ [ 2 ], [ 2, 3 ] ], - [ [ 2 ], [ 2 ], [ 2 ], [ 2 ], [ 3 ], [ 3 ], [ 3 ], [ 3 ] ], - [ [ 9, 0, 9 ], [ 0, 9, 0 ] ], - [ [ 9, 9, 9 ], [ 0, 9, 9 ] ], - [ [ 9, 0, 9 ], [ 9, 9, 9 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 0 ] ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.strictEqual( actual, null, 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); From 26f379b5148868c307eb5c3f4252556b16f8e6e4 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Jun 2024 01:56:46 +0000 Subject: [PATCH 103/158] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index e256077..a53e06e 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,8 @@ }, "dependencies": { "@stdlib/types": "^0.3.2", - "@stdlib/utils-library-manifest": "^0.2.1" + "@stdlib/utils-library-manifest": "^0.2.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1" }, "devDependencies": { "@stdlib/string-left-pad": "^0.2.1", @@ -84,4 +85,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From 9735889efd05caaeafc1deaac2afcbed58d08570 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Jun 2024 03:17:35 +0000 Subject: [PATCH 104/158] Remove files --- browser.js | 3 - browser.js.map | 1 - index.js | 3 - index.js.map | 1 - stats_browser.html | 4842 -------------------------------------------- stats_node.html | 4842 -------------------------------------------- 6 files changed, 9692 deletions(-) delete mode 100644 browser.js delete mode 100644 browser.js.map delete mode 100644 index.js delete mode 100644 index.js.map delete mode 100644 stats_browser.html delete mode 100644 stats_node.html diff --git a/browser.js b/browser.js deleted file mode 100644 index 44a8074..0000000 --- a/browser.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); -//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map deleted file mode 100644 index aa4b2bb..0000000 --- a/browser.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"browser.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/index.js b/index.js deleted file mode 100644 index d225eb4..0000000 --- a/index.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); -//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map deleted file mode 100644 index 0c02c0f..0000000 --- a/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/stats_browser.html b/stats_browser.html deleted file mode 100644 index 2f35700..0000000 --- a/stats_browser.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - diff --git a/stats_node.html b/stats_node.html deleted file mode 100644 index c264c7d..0000000 --- a/stats_node.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 3f52b72b02b2d4eb4d457797e813c22edcab581f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Jun 2024 03:17:48 +0000 Subject: [PATCH 105/158] 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 | 248 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .gitignore | 188 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 178 +- SECURITY.md | 5 - benchmark/benchmark.js | 112 - benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 152 - branches.md | 56 - browser.js | 3 + browser.js.map | 1 + dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 39 - docs/types/index.d.ts | 177 - docs/types/test.ts | 45 - examples/c/Makefile | 146 - examples/c/example.c | 50 - examples/index.js | 54 - .../stdlib/ndarray/base/broadcast_shapes.h | 40 - index.js | 3 + index.js.map | 1 + lib/index.js | 45 - lib/main.js | 256 - manifest.json | 38 - package.json | 58 +- src/main.c | 118 - stats_browser.html | 4842 +++++++++++++++++ stats_node.html | 4842 +++++++++++++++++ test/dist/test.js | 33 - test/test.js | 230 - 53 files changed, 9729 insertions(+), 5131 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.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 branches.md create mode 100644 browser.js create mode 100644 browser.js.map 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/index.d.ts delete mode 100644 docs/types/test.ts delete mode 100644 examples/c/Makefile delete mode 100644 examples/c/example.c delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/broadcast_shapes.h create mode 100644 index.js create mode 100644 index.js.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 manifest.json delete mode 100644 src/main.c create mode 100644 stats_browser.html create mode 100644 stats_node.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/.keepalive b/.github/.keepalive deleted file mode 100644 index 1f1b051..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-06-01T01:28:49.247Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 7f004ad..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 a07d970..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 7292af0..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: '0 12 * * 5' - - # 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 +``` -```javascript -var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); +If no recognized module system is present, access bundle contents via the global scope: + +```html + ``` #### broadcastShapes( shapes ) @@ -245,9 +251,14 @@ var sh = broadcastShapes( [ sh1, sh2 ] ); -```javascript -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); +```html + + + + + + + + ```
@@ -288,131 +304,7 @@ for ( i = 0; i < shapes.length; i++ ) { -* * * - -
- -## C APIs - - - -
- -
- - - - - -
- -### Usage - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -``` - -#### stdlib_ndarray_broadcast_shapes( M, \*\*shapes, \*ndims, \*out ) - -Broadcasts array shapes to a single shape. - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -int64_t N1 = 4; -int64_t sh1[] = { 8, 1, 6, 1 }; - -int64_t N2 = 3; -int64_t sh2[] = { 7, 1, 5 }; - -int64_t ndims[] = { N1, N2 }; -int64_t *shapes[] = { sh1, sh2 }; - -int64_t out[] = { 0, 0, 0, 0 }; -int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -if ( status != 0 ) { - // Handle error... -} -``` - -The function accepts the following arguments: - -- **M**: `[in] int64_t` number of shape arrays. -- **shapes**: `[in] int64_t**` array of shape arrays (dimensions). -- **ndims**: `[in] int64_t*` number of dimensions for each respective shape array. -- **out**: `[out] int64_t*` output shape array. - -```c -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ); -``` - -If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). - -
- - - - - -
- -### Notes - -- Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. - -
- - - - - -
- -### Examples - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main( void ) { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} -``` - -
- - - -
- 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.js b/benchmark/benchmark.js deleted file mode 100644 index 6426216..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,112 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pkg = require( './../package.json' ).name; -var broadcastShapes = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::two_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ] ], - [ [ 3, 2 ], [ 3, 1 ] ], - [ [ 1, 1 ], [ 2, 2 ] ], - [ [ 1 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::three_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::four_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ], [ 8, 1, 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ], [ 1, 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ], [ 1, 1, 2, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ], [ 1 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ], [ 5, 1, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/c/Makefile b/benchmark/c/Makefile deleted file mode 100644 index 5dc545c..0000000 --- a/benchmark/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := benchmark.out - - -# RULES # - -#/ -# Compiles C source files. -# -# @param {string} SOURCE_FILES - list of C source files -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lpthread -lblas`) -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [C_COMPILER] - C compiler -# @param {string} [CFLAGS] - C compiler flags -# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} SOURCE_FILES - list of C source files -# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {(string|void)} LIBRARIES - list of libraries (e.g., `-lpthread -lblas`) -# @param {(string|void)} LIBPATH - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} CC - C compiler -# @param {string} CFLAGS - C compiler flags -# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled benchmarks. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/benchmark/c/benchmark.c b/benchmark/c/benchmark.c deleted file mode 100644 index be62cd5..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,152 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/** -* Benchmark `broadcast_shapes`. -*/ -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "broadcast-shapes" -#define ITERATIONS 1000000 -#define REPEATS 3 - -/** -* Prints the TAP version. -*/ -void print_version() { - printf( "TAP version 13\n" ); -} - -/** -* Prints the TAP summary. -* -* @param total total number of tests -* @param passing total number of passing tests -*/ -void print_summary( int total, int passing ) { - printf( "#\n" ); - printf( "1..%d\n", total ); // TAP plan - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); -} - -/** -* Prints benchmarks results. -* -* @param elapsed elapsed time in seconds -*/ -void print_results( double elapsed ) { - double rate = (double)ITERATIONS / elapsed; - printf( " ---\n" ); - printf( " iterations: %d\n", ITERATIONS ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", rate ); - printf( " ...\n" ); -} - -/** -* Returns a clock time. -* -* @return clock time -*/ -double tic() { - struct timeval now; - gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; -} - -/** -* Generates a random double on the interval [0,1]. -* -* @return random double -*/ -double rand_double() { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark() { - double elapsed; - int8_t status; - double t; - int i; - - int64_t sh1[] = { 8, 1, 6, 1 }; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { 4, 3 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( out[ 0 ] != 8 ) { - printf( "unexpected result\n" ); - } - if ( out[ 1 ] != 7 ) { - printf( "unexpected result\n" ); - } - if ( out[ 2 ] != 6 ) { - printf( "unexpected result\n" ); - } - if ( out[ 3 ] != 5 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Main execution sequence. -*/ -int main( void ) { - double elapsed; - int i; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - for ( i = 0; i < REPEATS; i++ ) { - printf( "# c::native::%s::two_arrays\n", NAME ); - elapsed = benchmark(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", i+1 ); - } - print_summary( REPEATS, REPEATS ); -} diff --git a/branches.md b/branches.md deleted file mode 100644 index 79909c9..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes" -%% click B href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/blob/esm/README.md \ No newline at end of file diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..44a8074 --- /dev/null +++ b/browser.js @@ -0,0 +1,3 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map new file mode 100644 index 0000000..aa4b2bb --- /dev/null +++ b/browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"browser.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 87ea8b6..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import broadcastShapes from '../docs/types/index'; -export = broadcastShapes; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 625741a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var d=function(t,e){return function(){return e||t((e={exports:{}}).exports,e),e.exports}};var h=d(function(x,c){ -function g(t){var e,n,u,o,s,l,a,f,i,r,v;if(f=t.length,n=[],f===0)return n;if(o=t[0],i=o.length,f===1){for(r=0;ri&&(i=e[r]);for(r=0;r=0;){for(s=e[0]-i+r,s>=0?u=o[s]:u=1,v=1;v=0?a=t[v][l]:a=1,u===1){u=a;continue}if(!(a===1||u===a))return null}n[r]=u,r-=1}return n}c.exports=g -});var m=h();module.exports=m; -/** @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 db2949f..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = broadcastShapes;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast array shapes to a single shape.\n*\n* @module @stdlib/ndarray-base-broadcast-shapes\n*\n* @example\n* var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' );\n*\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\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,cAkLA,SAASC,EAAiBC,EAAS,CAClC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GAFAH,EAAIR,EAAO,OACXE,EAAM,CAAC,EACFM,IAAM,EACV,OAAON,EAMR,GAJAE,EAAKJ,EAAQ,CAAE,EACfS,EAAIL,EAAG,OAGFI,IAAM,EAAI,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAI,KAAME,EAAIM,CAAE,CAAE,EAEnB,OAAOR,CACR,CAGA,IADAD,EAAQ,CAAEQ,CAAE,EACNC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAM,KAAMD,EAAQU,CAAE,EAAE,MAAO,EAC1BT,EAAOS,CAAE,EAAID,IACjBA,EAAIR,EAAOS,CAAE,GAIf,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAI,KAAM,CAAE,EAIb,IADAQ,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IANAL,EAAKJ,EAAO,CAAE,EAAIQ,EAAIC,EACjBL,GAAM,EACVF,EAAMC,EAAIC,CAAG,EAEbF,EAAM,EAEDQ,EAAI,EAAGA,EAAIH,EAAGG,IAAM,CAOzB,GANAL,EAAKL,EAAOU,CAAE,EAAIF,EAAIC,EACjBJ,GAAM,EACVC,EAAIP,EAAQW,CAAE,EAAGL,CAAG,EAEpBC,EAAI,EAEAJ,IAAQ,EAAI,CAChBA,EAAMI,EACN,QACD,CACA,GAAK,EAAAA,IAAM,GAAKJ,IAAQI,GAKxB,OAAO,IACR,CACAL,EAAKQ,CAAE,EAAIP,EACXO,GAAK,CACN,CACA,OAAOR,CACR,CAKAJ,EAAO,QAAUC,ICxNjB,IAAIa,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "broadcastShapes", "shapes", "ndims", "out", "dim", "sh", "n1", "n2", "d", "M", "N", "i", "j", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f1d92f6..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,39 +0,0 @@ - -{{alias}}( shapes ) - Broadcasts array shapes to a single shape. - - Two respective dimensions in two shape arrays are compatible if - - 1. the dimensions are equal. - 2. one dimension is `1`. - - The function returns `null` if provided incompatible shapes (i.e., shapes - which cannot be broadcast with one another). - - Parameters - ---------- - shapes: Array - Array of shape arrays. - - Returns - ------- - out: Array|null - Broadcast shape. - - Examples - -------- - // Compatible shapes: - > var sh1 = [ 8, 1, 6, 1 ]; - > var sh2 = [ 7, 1, 5 ]; - > var sh = {{alias}}( [ sh1, sh2 ] ) - [ 8, 7, 6, 5 ] - - // Incompatible shapes: - > sh1 = [ 3, 2 ]; - > sh1 = [ 2, 3 ]; - > sh = {{alias}}( [ sh1, sh2 ] ) - null - - See Also - -------- - diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts deleted file mode 100644 index c2702cf..0000000 --- a/docs/types/index.d.ts +++ /dev/null @@ -1,177 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ArrayLike } from '@stdlib/types/array'; - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param shapes - array shapes -* @returns broadcast shape -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -declare function broadcastShapes( shapes: ArrayLike> ): ArrayLike; - - -// EXPORTS // - -export = broadcastShapes; diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 2886539..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 broadcastShapes = require( './index' ); - - -// TESTS // - -// The function returns an array of numbers... -{ - broadcastShapes( [ [ 1, 2 ], [ 2, 2 ] ] ); // $ExpectType ArrayLike -} - -// The compiler throws an error if the function is not provided an array-like object containing array-like objects containing numbers... -{ - broadcastShapes( '5' ); // $ExpectError - broadcastShapes( 5 ); // $ExpectError - broadcastShapes( true ); // $ExpectError - broadcastShapes( false ); // $ExpectError - broadcastShapes( null ); // $ExpectError - broadcastShapes( {} ); // $ExpectError - broadcastShapes( [ '5' ] ); // $ExpectError - broadcastShapes( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - broadcastShapes(); // $ExpectError - broadcastShapes( [ [ 1, 2, 3 ] ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/c/Makefile b/examples/c/Makefile deleted file mode 100644 index 70c91f4..0000000 --- a/examples/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := example.out - - -# RULES # - -#/ -# Compiles source files. -# -# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) -# @param {string} [CFLAGS] - C compiler options -# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) -# @param {string} [SOURCE_FILES] - list of source files -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} CC - C compiler (e.g., `gcc`) -# @param {string} CFLAGS - C compiler options -# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) -# @param {string} SOURCE_FILES - list of source files -# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) -# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled examples. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/examples/c/example.c b/examples/c/example.c deleted file mode 100644 index 4bc54d5..0000000 --- a/examples/c/example.c +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main( void ) { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 28811f9..0000000 --- a/examples/index.js +++ /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. -*/ - -'use strict'; - -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( './../lib' ); - -var shapes; -var out; -var sh; -var i; -var j; - -function shape2string( shape ) { - return lpad( shape.join( ' x ' ), 20, ' ' ); -} - -shapes = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] -]; - -for ( i = 0; i < shapes.length; i++ ) { - sh = shapes[ i ]; - for ( j = 0; j < sh.length; j++ ) { - console.log( shape2string( sh[ j ] ) ); - } - console.log( lpad( '', 20, '-' ) ); - - out = broadcastShapes( sh ); - console.log( shape2string( out )+'\n' ); -} diff --git a/include/stdlib/ndarray/base/broadcast_shapes.h b/include/stdlib/ndarray/base/broadcast_shapes.h deleted file mode 100644 index e23dce1..0000000 --- a/include/stdlib/ndarray/base/broadcast_shapes.h +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#ifndef STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H -#define STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H - -#include - -/* -* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. -*/ -#ifdef __cplusplus -extern "C" { -#endif - -/** -* Broadcasts array shapes to a single shape. -*/ -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H diff --git a/index.js b/index.js new file mode 100644 index 0000000..d225eb4 --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map new file mode 100644 index 0000000..0c02c0f --- /dev/null +++ b/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 0c9817e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Broadcast array shapes to a single shape. -* -* @module @stdlib/ndarray-base-broadcast-shapes -* -* @example -* var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); -* -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -*/ - -// 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 8558e60..0000000 --- a/lib/main.js +++ /dev/null @@ -1,256 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param {Array} shapes - array of shape arrays -* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`) -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [ 8, 0, 1, 6, 1 ], -* [ 8, 8, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -function broadcastShapes( shapes ) { - var ndims; - var out; - var dim; - var sh; - var n1; - var n2; - var d; - var M; - var N; - var i; - var j; - - M = shapes.length; - out = []; - if ( M === 0 ) { - return out; - } - sh = shapes[ 0 ]; - N = sh.length; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M === 1 ) { - // Need to manually copy to output shape, as shapes could be array-like objects... - for ( i = 0; i < N; i++ ) { - out.push( sh[ i ] ); - } - return out; - } - // Determine the maximum dimensionality... - ndims = [ N ]; - for ( i = 1; i < M; i++ ) { - ndims.push( shapes[ i ].length ); - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Initialize the output array... - for ( i = 0; i < N; i++ ) { - out.push( 0 ); - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim === 1 ) { - dim = d; - continue; - } - if ( d === 1 || dim === d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return null; - } - out[ i ] = dim; - i -= 1; - } - return out; -} - - -// EXPORTS // - -module.exports = broadcastShapes; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 890a937..0000000 --- a/manifest.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "options": {}, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [] - } - ] -} diff --git a/package.json b/package.json index a53e06e..0b77b65 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,7 @@ "version": "0.2.1", "description": "Broadcast array shapes to a single shape.", "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", - "include": "./include", - "lib": "./lib", - "src": "./src", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "main": "./index.js", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,33 +12,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/types": "^0.3.2", - "@stdlib/utils-library-manifest": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/string-left-pad": "^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", "stdtypes", @@ -80,9 +27,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 35a3654..0000000 --- a/src/main.c +++ /dev/null @@ -1,118 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). -* -* - Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. -* -* @param M number of array shapes -* @param shapes pointer to an array containing shape arrays -* @param ndims array containing the number of dimensions for (i.e., length of) each respective shape array -* @param out pointer to output array -* @return status -* -* @example -* #include "stdlib/ndarray/base/broadcast_shapes.h" -* #include -* -* int64_t N1 = 4; -* int64_t sh1[] = { 8, 1, 6, 1 }; -* -* int64_t N2 = 3; -* int64_t sh2[] = { 7, 1, 5 }; -* -* int64_t ndims[] = { N1, N2 }; -* int64_t *shapes[] = { sh1, sh2 }; -* -* int64_t out[] = { 0, 0, 0, 0 }; -* int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -*/ -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ) { - int64_t dim; - int64_t *sh; - int64_t n1; - int64_t n2; - int64_t d; - int64_t N; - int64_t i; - int64_t j; - - if ( M == 0 ) { - return 0; - } - sh = shapes[ 0 ]; - N = ndims[ 0 ]; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M == 1 ) { - for ( i = 0; i < N; i++ ) { - out[ i ] = sh[ i ]; - } - return 0; - } - // Determine the maximum dimensionality... - for ( i = 1; i < M; i++ ) { - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim == 1 ) { - dim = d; - continue; - } - if ( d == 1 || dim == d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return -1; - } - out[ i ] = dim; - i -= 1; - } - return 0; -} diff --git a/stats_browser.html b/stats_browser.html new file mode 100644 index 0000000..2f35700 --- /dev/null +++ b/stats_browser.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/stats_node.html b/stats_node.html new file mode 100644 index 0000000..c264c7d --- /dev/null +++ b/stats_node.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 63f703c..0000000 --- a/test/test.js +++ /dev/null @@ -1,230 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var broadcastShapes = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastShapes, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] - ]; - - expected = [ - [ 1, 2 ], - [ 3, 4 ], - [ 5, 6, 7 ], - [ 3, 3 ], - [ 3 ], - [ 3, 2 ], - [ 2, 3 ], - [ 1, 2 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty dims)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 0 ], [ 0, 0 ] ], - [ [ 0, 1 ], [ 0, 0 ] ], - [ [ 1, 0 ], [ 0, 1 ] ], - [ [ 1, 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 1, 0 ] ], - [ [ 1, 1 ], [ 0, 1 ] ], - [ [ 0 ], [ 0, 0 ] ], - [ [ 0 ], [ 0, 1 ] ], - [ [ 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 0 ] ], - [ [ 1 ], [ 0, 1 ] ], - [ [ 1 ], [ 1, 0 ] ], - [ [ 1 ], [ 8, 0 ] ], - [ [ 8, 1, 6, 1 ], [ 0, 1, 5 ] ], - [ [ 8, 0, 6, 1 ], [ 1, 5 ] ] - ]; - - expected = [ - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 1, 0 ], - [ 8, 0 ], - [ 8, 0, 6, 5 ], - [ 8, 0, 6, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (no shapes)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [] - ]; - - expected = [ - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty shapes (i.e., zero-dimensional array broadcasting))', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [] ], - [ [], [] ], - [ [], [], [] ], - [ [], [ 0 ] ], - [ [ 0 ], [] ], - [ [], [ 0, 0 ] ], - [ [ 0, 0 ], [] ], - [ [], [ 1, 0 ] ], - [ [], [ 0, 1 ] ], - [ [], [ 3, 3 ] ], - [ [], [ 3, 3 ], [] ] - ]; - - expected = [ - [], - [], - [], - [ 0 ], - [ 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 3, 3 ], - [ 3, 3 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (single shape)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 7 ] ], - [ [ 1, 1 ] ], - [ [ 5, 6, 1 ] ] - ]; - - expected = [ - [ 7 ], - [ 1, 1 ], - [ 5, 6, 1 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function returns `null` if provided incompatible shapes', function test( t ) { - var actual; - var values; - var i; - - values = [ - [ [ 3 ], [ 4 ] ], - [ [ 2, 3 ], [ 2 ] ], - [ [ 3 ], [ 3 ], [ 4 ] ], - [ [ 1, 3, 4 ], [ 2, 3, 3 ] ], - [ [ 1, 2 ], [ 3, 1 ], [ 3, 2 ], [ 10, 5 ] ], - [ [ 2 ], [ 2, 3 ] ], - [ [ 2 ], [ 2 ], [ 2 ], [ 2 ], [ 3 ], [ 3 ], [ 3 ], [ 3 ] ], - [ [ 9, 0, 9 ], [ 0, 9, 0 ] ], - [ [ 9, 9, 9 ], [ 0, 9, 9 ] ], - [ [ 9, 0, 9 ], [ 9, 9, 9 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 0 ] ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.strictEqual( actual, null, 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); From acb1140b4b97f3f49f01636d4d793d2a624a5a25 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jul 2024 01:54:28 +0000 Subject: [PATCH 106/158] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index e256077..a53e06e 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,8 @@ }, "dependencies": { "@stdlib/types": "^0.3.2", - "@stdlib/utils-library-manifest": "^0.2.1" + "@stdlib/utils-library-manifest": "^0.2.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1" }, "devDependencies": { "@stdlib/string-left-pad": "^0.2.1", @@ -84,4 +85,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From c811e40e349dce2225b20a1f948d97029982497f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jul 2024 03:23:38 +0000 Subject: [PATCH 107/158] Remove files --- browser.js | 3 - browser.js.map | 1 - index.js | 3 - index.js.map | 1 - stats_browser.html | 4842 -------------------------------------------- stats_node.html | 4842 -------------------------------------------- 6 files changed, 9692 deletions(-) delete mode 100644 browser.js delete mode 100644 browser.js.map delete mode 100644 index.js delete mode 100644 index.js.map delete mode 100644 stats_browser.html delete mode 100644 stats_node.html diff --git a/browser.js b/browser.js deleted file mode 100644 index 44a8074..0000000 --- a/browser.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); -//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map deleted file mode 100644 index aa4b2bb..0000000 --- a/browser.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"browser.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/index.js b/index.js deleted file mode 100644 index d225eb4..0000000 --- a/index.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); -//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map deleted file mode 100644 index 0c02c0f..0000000 --- a/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/stats_browser.html b/stats_browser.html deleted file mode 100644 index 2f35700..0000000 --- a/stats_browser.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - diff --git a/stats_node.html b/stats_node.html deleted file mode 100644 index c264c7d..0000000 --- a/stats_node.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 5edb1df9961f4e9f98cb9497de5b9bfdddbc3b83 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jul 2024 03:23:55 +0000 Subject: [PATCH 108/158] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .gitignore | 188 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 38 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 178 +- SECURITY.md | 5 - benchmark/benchmark.js | 112 - benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 152 - branches.md | 56 - browser.js | 3 + browser.js.map | 1 + dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 39 - docs/types/index.d.ts | 177 - docs/types/test.ts | 45 - examples/c/Makefile | 146 - examples/c/example.c | 50 - examples/index.js | 54 - .../stdlib/ndarray/base/broadcast_shapes.h | 40 - index.js | 3 + index.js.map | 1 + lib/index.js | 45 - lib/main.js | 256 - manifest.json | 38 - package.json | 58 +- src/main.c | 118 - stats_browser.html | 4842 +++++++++++++++++ stats_node.html | 4842 +++++++++++++++++ test/dist/test.js | 33 - test/test.js | 230 - 53 files changed, 9729 insertions(+), 5168 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.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 branches.md create mode 100644 browser.js create mode 100644 browser.js.map 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/index.d.ts delete mode 100644 docs/types/test.ts delete mode 100644 examples/c/Makefile delete mode 100644 examples/c/example.c delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/broadcast_shapes.h create mode 100644 index.js create mode 100644 index.js.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 manifest.json delete mode 100644 src/main.c create mode 100644 stats_browser.html create mode 100644 stats_node.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/.keepalive b/.github/.keepalive deleted file mode 100644 index fa54726..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-07-01T01:25:22.256Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 7f004ad..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 a07d970..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 7292af0..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: '0 12 * * 5' - - # 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 +``` -```javascript -var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); +If no recognized module system is present, access bundle contents via the global scope: + +```html + ``` #### broadcastShapes( shapes ) @@ -245,9 +251,14 @@ var sh = broadcastShapes( [ sh1, sh2 ] ); -```javascript -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); +```html + + + + + + + + ```
@@ -288,131 +304,7 @@ for ( i = 0; i < shapes.length; i++ ) { -* * * - -
- -## C APIs - - - -
- -
- - - - - -
- -### Usage - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -``` - -#### stdlib_ndarray_broadcast_shapes( M, \*\*shapes, \*ndims, \*out ) - -Broadcasts array shapes to a single shape. - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -int64_t N1 = 4; -int64_t sh1[] = { 8, 1, 6, 1 }; - -int64_t N2 = 3; -int64_t sh2[] = { 7, 1, 5 }; - -int64_t ndims[] = { N1, N2 }; -int64_t *shapes[] = { sh1, sh2 }; - -int64_t out[] = { 0, 0, 0, 0 }; -int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -if ( status != 0 ) { - // Handle error... -} -``` - -The function accepts the following arguments: - -- **M**: `[in] int64_t` number of shape arrays. -- **shapes**: `[in] int64_t**` array of shape arrays (dimensions). -- **ndims**: `[in] int64_t*` number of dimensions for each respective shape array. -- **out**: `[out] int64_t*` output shape array. - -```c -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ); -``` - -If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). - -
- - - - - -
- -### Notes - -- Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. - -
- - - - - -
- -### Examples - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main( void ) { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} -``` - -
- - - -
- 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.js b/benchmark/benchmark.js deleted file mode 100644 index 6426216..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,112 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pkg = require( './../package.json' ).name; -var broadcastShapes = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::two_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ] ], - [ [ 3, 2 ], [ 3, 1 ] ], - [ [ 1, 1 ], [ 2, 2 ] ], - [ [ 1 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::three_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::four_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ], [ 8, 1, 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ], [ 1, 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ], [ 1, 1, 2, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ], [ 1 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ], [ 5, 1, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/c/Makefile b/benchmark/c/Makefile deleted file mode 100644 index 5dc545c..0000000 --- a/benchmark/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := benchmark.out - - -# RULES # - -#/ -# Compiles C source files. -# -# @param {string} SOURCE_FILES - list of C source files -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lpthread -lblas`) -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [C_COMPILER] - C compiler -# @param {string} [CFLAGS] - C compiler flags -# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} SOURCE_FILES - list of C source files -# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {(string|void)} LIBRARIES - list of libraries (e.g., `-lpthread -lblas`) -# @param {(string|void)} LIBPATH - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} CC - C compiler -# @param {string} CFLAGS - C compiler flags -# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled benchmarks. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/benchmark/c/benchmark.c b/benchmark/c/benchmark.c deleted file mode 100644 index be62cd5..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,152 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/** -* Benchmark `broadcast_shapes`. -*/ -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "broadcast-shapes" -#define ITERATIONS 1000000 -#define REPEATS 3 - -/** -* Prints the TAP version. -*/ -void print_version() { - printf( "TAP version 13\n" ); -} - -/** -* Prints the TAP summary. -* -* @param total total number of tests -* @param passing total number of passing tests -*/ -void print_summary( int total, int passing ) { - printf( "#\n" ); - printf( "1..%d\n", total ); // TAP plan - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); -} - -/** -* Prints benchmarks results. -* -* @param elapsed elapsed time in seconds -*/ -void print_results( double elapsed ) { - double rate = (double)ITERATIONS / elapsed; - printf( " ---\n" ); - printf( " iterations: %d\n", ITERATIONS ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", rate ); - printf( " ...\n" ); -} - -/** -* Returns a clock time. -* -* @return clock time -*/ -double tic() { - struct timeval now; - gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; -} - -/** -* Generates a random double on the interval [0,1]. -* -* @return random double -*/ -double rand_double() { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark() { - double elapsed; - int8_t status; - double t; - int i; - - int64_t sh1[] = { 8, 1, 6, 1 }; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { 4, 3 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( out[ 0 ] != 8 ) { - printf( "unexpected result\n" ); - } - if ( out[ 1 ] != 7 ) { - printf( "unexpected result\n" ); - } - if ( out[ 2 ] != 6 ) { - printf( "unexpected result\n" ); - } - if ( out[ 3 ] != 5 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Main execution sequence. -*/ -int main( void ) { - double elapsed; - int i; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - for ( i = 0; i < REPEATS; i++ ) { - printf( "# c::native::%s::two_arrays\n", NAME ); - elapsed = benchmark(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", i+1 ); - } - print_summary( REPEATS, REPEATS ); -} diff --git a/branches.md b/branches.md deleted file mode 100644 index 79909c9..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes" -%% click B href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/blob/esm/README.md \ No newline at end of file diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..44a8074 --- /dev/null +++ b/browser.js @@ -0,0 +1,3 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map new file mode 100644 index 0000000..aa4b2bb --- /dev/null +++ b/browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"browser.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 87ea8b6..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import broadcastShapes from '../docs/types/index'; -export = broadcastShapes; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 625741a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var d=function(t,e){return function(){return e||t((e={exports:{}}).exports,e),e.exports}};var h=d(function(x,c){ -function g(t){var e,n,u,o,s,l,a,f,i,r,v;if(f=t.length,n=[],f===0)return n;if(o=t[0],i=o.length,f===1){for(r=0;ri&&(i=e[r]);for(r=0;r=0;){for(s=e[0]-i+r,s>=0?u=o[s]:u=1,v=1;v=0?a=t[v][l]:a=1,u===1){u=a;continue}if(!(a===1||u===a))return null}n[r]=u,r-=1}return n}c.exports=g -});var m=h();module.exports=m; -/** @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 db2949f..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = broadcastShapes;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast array shapes to a single shape.\n*\n* @module @stdlib/ndarray-base-broadcast-shapes\n*\n* @example\n* var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' );\n*\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\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,cAkLA,SAASC,EAAiBC,EAAS,CAClC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GAFAH,EAAIR,EAAO,OACXE,EAAM,CAAC,EACFM,IAAM,EACV,OAAON,EAMR,GAJAE,EAAKJ,EAAQ,CAAE,EACfS,EAAIL,EAAG,OAGFI,IAAM,EAAI,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAI,KAAME,EAAIM,CAAE,CAAE,EAEnB,OAAOR,CACR,CAGA,IADAD,EAAQ,CAAEQ,CAAE,EACNC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAM,KAAMD,EAAQU,CAAE,EAAE,MAAO,EAC1BT,EAAOS,CAAE,EAAID,IACjBA,EAAIR,EAAOS,CAAE,GAIf,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAI,KAAM,CAAE,EAIb,IADAQ,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IANAL,EAAKJ,EAAO,CAAE,EAAIQ,EAAIC,EACjBL,GAAM,EACVF,EAAMC,EAAIC,CAAG,EAEbF,EAAM,EAEDQ,EAAI,EAAGA,EAAIH,EAAGG,IAAM,CAOzB,GANAL,EAAKL,EAAOU,CAAE,EAAIF,EAAIC,EACjBJ,GAAM,EACVC,EAAIP,EAAQW,CAAE,EAAGL,CAAG,EAEpBC,EAAI,EAEAJ,IAAQ,EAAI,CAChBA,EAAMI,EACN,QACD,CACA,GAAK,EAAAA,IAAM,GAAKJ,IAAQI,GAKxB,OAAO,IACR,CACAL,EAAKQ,CAAE,EAAIP,EACXO,GAAK,CACN,CACA,OAAOR,CACR,CAKAJ,EAAO,QAAUC,ICxNjB,IAAIa,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "broadcastShapes", "shapes", "ndims", "out", "dim", "sh", "n1", "n2", "d", "M", "N", "i", "j", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f1d92f6..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,39 +0,0 @@ - -{{alias}}( shapes ) - Broadcasts array shapes to a single shape. - - Two respective dimensions in two shape arrays are compatible if - - 1. the dimensions are equal. - 2. one dimension is `1`. - - The function returns `null` if provided incompatible shapes (i.e., shapes - which cannot be broadcast with one another). - - Parameters - ---------- - shapes: Array - Array of shape arrays. - - Returns - ------- - out: Array|null - Broadcast shape. - - Examples - -------- - // Compatible shapes: - > var sh1 = [ 8, 1, 6, 1 ]; - > var sh2 = [ 7, 1, 5 ]; - > var sh = {{alias}}( [ sh1, sh2 ] ) - [ 8, 7, 6, 5 ] - - // Incompatible shapes: - > sh1 = [ 3, 2 ]; - > sh1 = [ 2, 3 ]; - > sh = {{alias}}( [ sh1, sh2 ] ) - null - - See Also - -------- - diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts deleted file mode 100644 index c2702cf..0000000 --- a/docs/types/index.d.ts +++ /dev/null @@ -1,177 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ArrayLike } from '@stdlib/types/array'; - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param shapes - array shapes -* @returns broadcast shape -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -declare function broadcastShapes( shapes: ArrayLike> ): ArrayLike; - - -// EXPORTS // - -export = broadcastShapes; diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 2886539..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 broadcastShapes = require( './index' ); - - -// TESTS // - -// The function returns an array of numbers... -{ - broadcastShapes( [ [ 1, 2 ], [ 2, 2 ] ] ); // $ExpectType ArrayLike -} - -// The compiler throws an error if the function is not provided an array-like object containing array-like objects containing numbers... -{ - broadcastShapes( '5' ); // $ExpectError - broadcastShapes( 5 ); // $ExpectError - broadcastShapes( true ); // $ExpectError - broadcastShapes( false ); // $ExpectError - broadcastShapes( null ); // $ExpectError - broadcastShapes( {} ); // $ExpectError - broadcastShapes( [ '5' ] ); // $ExpectError - broadcastShapes( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - broadcastShapes(); // $ExpectError - broadcastShapes( [ [ 1, 2, 3 ] ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/c/Makefile b/examples/c/Makefile deleted file mode 100644 index 70c91f4..0000000 --- a/examples/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := example.out - - -# RULES # - -#/ -# Compiles source files. -# -# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) -# @param {string} [CFLAGS] - C compiler options -# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) -# @param {string} [SOURCE_FILES] - list of source files -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} CC - C compiler (e.g., `gcc`) -# @param {string} CFLAGS - C compiler options -# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) -# @param {string} SOURCE_FILES - list of source files -# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) -# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled examples. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/examples/c/example.c b/examples/c/example.c deleted file mode 100644 index 4bc54d5..0000000 --- a/examples/c/example.c +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main( void ) { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 28811f9..0000000 --- a/examples/index.js +++ /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. -*/ - -'use strict'; - -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( './../lib' ); - -var shapes; -var out; -var sh; -var i; -var j; - -function shape2string( shape ) { - return lpad( shape.join( ' x ' ), 20, ' ' ); -} - -shapes = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] -]; - -for ( i = 0; i < shapes.length; i++ ) { - sh = shapes[ i ]; - for ( j = 0; j < sh.length; j++ ) { - console.log( shape2string( sh[ j ] ) ); - } - console.log( lpad( '', 20, '-' ) ); - - out = broadcastShapes( sh ); - console.log( shape2string( out )+'\n' ); -} diff --git a/include/stdlib/ndarray/base/broadcast_shapes.h b/include/stdlib/ndarray/base/broadcast_shapes.h deleted file mode 100644 index e23dce1..0000000 --- a/include/stdlib/ndarray/base/broadcast_shapes.h +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#ifndef STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H -#define STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H - -#include - -/* -* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. -*/ -#ifdef __cplusplus -extern "C" { -#endif - -/** -* Broadcasts array shapes to a single shape. -*/ -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H diff --git a/index.js b/index.js new file mode 100644 index 0000000..d225eb4 --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map new file mode 100644 index 0000000..0c02c0f --- /dev/null +++ b/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 0c9817e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Broadcast array shapes to a single shape. -* -* @module @stdlib/ndarray-base-broadcast-shapes -* -* @example -* var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); -* -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -*/ - -// 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 8558e60..0000000 --- a/lib/main.js +++ /dev/null @@ -1,256 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param {Array} shapes - array of shape arrays -* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`) -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [ 8, 0, 1, 6, 1 ], -* [ 8, 8, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -function broadcastShapes( shapes ) { - var ndims; - var out; - var dim; - var sh; - var n1; - var n2; - var d; - var M; - var N; - var i; - var j; - - M = shapes.length; - out = []; - if ( M === 0 ) { - return out; - } - sh = shapes[ 0 ]; - N = sh.length; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M === 1 ) { - // Need to manually copy to output shape, as shapes could be array-like objects... - for ( i = 0; i < N; i++ ) { - out.push( sh[ i ] ); - } - return out; - } - // Determine the maximum dimensionality... - ndims = [ N ]; - for ( i = 1; i < M; i++ ) { - ndims.push( shapes[ i ].length ); - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Initialize the output array... - for ( i = 0; i < N; i++ ) { - out.push( 0 ); - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim === 1 ) { - dim = d; - continue; - } - if ( d === 1 || dim === d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return null; - } - out[ i ] = dim; - i -= 1; - } - return out; -} - - -// EXPORTS // - -module.exports = broadcastShapes; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 890a937..0000000 --- a/manifest.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "options": {}, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [] - } - ] -} diff --git a/package.json b/package.json index a53e06e..0b77b65 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,7 @@ "version": "0.2.1", "description": "Broadcast array shapes to a single shape.", "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", - "include": "./include", - "lib": "./lib", - "src": "./src", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "main": "./index.js", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,33 +12,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/types": "^0.3.2", - "@stdlib/utils-library-manifest": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/string-left-pad": "^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", "stdtypes", @@ -80,9 +27,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 35a3654..0000000 --- a/src/main.c +++ /dev/null @@ -1,118 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). -* -* - Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. -* -* @param M number of array shapes -* @param shapes pointer to an array containing shape arrays -* @param ndims array containing the number of dimensions for (i.e., length of) each respective shape array -* @param out pointer to output array -* @return status -* -* @example -* #include "stdlib/ndarray/base/broadcast_shapes.h" -* #include -* -* int64_t N1 = 4; -* int64_t sh1[] = { 8, 1, 6, 1 }; -* -* int64_t N2 = 3; -* int64_t sh2[] = { 7, 1, 5 }; -* -* int64_t ndims[] = { N1, N2 }; -* int64_t *shapes[] = { sh1, sh2 }; -* -* int64_t out[] = { 0, 0, 0, 0 }; -* int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -*/ -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ) { - int64_t dim; - int64_t *sh; - int64_t n1; - int64_t n2; - int64_t d; - int64_t N; - int64_t i; - int64_t j; - - if ( M == 0 ) { - return 0; - } - sh = shapes[ 0 ]; - N = ndims[ 0 ]; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M == 1 ) { - for ( i = 0; i < N; i++ ) { - out[ i ] = sh[ i ]; - } - return 0; - } - // Determine the maximum dimensionality... - for ( i = 1; i < M; i++ ) { - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim == 1 ) { - dim = d; - continue; - } - if ( d == 1 || dim == d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return -1; - } - out[ i ] = dim; - i -= 1; - } - return 0; -} diff --git a/stats_browser.html b/stats_browser.html new file mode 100644 index 0000000..2f35700 --- /dev/null +++ b/stats_browser.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/stats_node.html b/stats_node.html new file mode 100644 index 0000000..c264c7d --- /dev/null +++ b/stats_node.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 63f703c..0000000 --- a/test/test.js +++ /dev/null @@ -1,230 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var broadcastShapes = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastShapes, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] - ]; - - expected = [ - [ 1, 2 ], - [ 3, 4 ], - [ 5, 6, 7 ], - [ 3, 3 ], - [ 3 ], - [ 3, 2 ], - [ 2, 3 ], - [ 1, 2 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty dims)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 0 ], [ 0, 0 ] ], - [ [ 0, 1 ], [ 0, 0 ] ], - [ [ 1, 0 ], [ 0, 1 ] ], - [ [ 1, 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 1, 0 ] ], - [ [ 1, 1 ], [ 0, 1 ] ], - [ [ 0 ], [ 0, 0 ] ], - [ [ 0 ], [ 0, 1 ] ], - [ [ 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 0 ] ], - [ [ 1 ], [ 0, 1 ] ], - [ [ 1 ], [ 1, 0 ] ], - [ [ 1 ], [ 8, 0 ] ], - [ [ 8, 1, 6, 1 ], [ 0, 1, 5 ] ], - [ [ 8, 0, 6, 1 ], [ 1, 5 ] ] - ]; - - expected = [ - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 1, 0 ], - [ 8, 0 ], - [ 8, 0, 6, 5 ], - [ 8, 0, 6, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (no shapes)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [] - ]; - - expected = [ - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty shapes (i.e., zero-dimensional array broadcasting))', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [] ], - [ [], [] ], - [ [], [], [] ], - [ [], [ 0 ] ], - [ [ 0 ], [] ], - [ [], [ 0, 0 ] ], - [ [ 0, 0 ], [] ], - [ [], [ 1, 0 ] ], - [ [], [ 0, 1 ] ], - [ [], [ 3, 3 ] ], - [ [], [ 3, 3 ], [] ] - ]; - - expected = [ - [], - [], - [], - [ 0 ], - [ 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 3, 3 ], - [ 3, 3 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (single shape)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 7 ] ], - [ [ 1, 1 ] ], - [ [ 5, 6, 1 ] ] - ]; - - expected = [ - [ 7 ], - [ 1, 1 ], - [ 5, 6, 1 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function returns `null` if provided incompatible shapes', function test( t ) { - var actual; - var values; - var i; - - values = [ - [ [ 3 ], [ 4 ] ], - [ [ 2, 3 ], [ 2 ] ], - [ [ 3 ], [ 3 ], [ 4 ] ], - [ [ 1, 3, 4 ], [ 2, 3, 3 ] ], - [ [ 1, 2 ], [ 3, 1 ], [ 3, 2 ], [ 10, 5 ] ], - [ [ 2 ], [ 2, 3 ] ], - [ [ 2 ], [ 2 ], [ 2 ], [ 2 ], [ 3 ], [ 3 ], [ 3 ], [ 3 ] ], - [ [ 9, 0, 9 ], [ 0, 9, 0 ] ], - [ [ 9, 9, 9 ], [ 0, 9, 9 ] ], - [ [ 9, 0, 9 ], [ 9, 9, 9 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 0 ] ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.strictEqual( actual, null, 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); From fa4407495d3f396ebdd67a3f7f3c0f1260e88748 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 27 Jul 2024 02:13:55 +0000 Subject: [PATCH 109/158] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 1ff7b0b..128b641 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,8 @@ }, "dependencies": { "@stdlib/types": "^0.3.2", - "@stdlib/utils-library-manifest": "^0.2.1" + "@stdlib/utils-library-manifest": "^0.2.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, "devDependencies": { "@stdlib/string-left-pad": "^0.2.1", @@ -84,4 +85,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From ea2ccd151c11b2d7e4df75b73166e5a611aa0b27 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 27 Jul 2024 02:35:15 +0000 Subject: [PATCH 110/158] Remove files --- browser.js | 3 - browser.js.map | 1 - index.js | 3 - index.js.map | 1 - stats_browser.html | 4842 -------------------------------------------- stats_node.html | 4842 -------------------------------------------- 6 files changed, 9692 deletions(-) delete mode 100644 browser.js delete mode 100644 browser.js.map delete mode 100644 index.js delete mode 100644 index.js.map delete mode 100644 stats_browser.html delete mode 100644 stats_node.html diff --git a/browser.js b/browser.js deleted file mode 100644 index 44a8074..0000000 --- a/browser.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); -//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map deleted file mode 100644 index aa4b2bb..0000000 --- a/browser.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"browser.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/index.js b/index.js deleted file mode 100644 index d225eb4..0000000 --- a/index.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); -//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map deleted file mode 100644 index 0c02c0f..0000000 --- a/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/stats_browser.html b/stats_browser.html deleted file mode 100644 index 2f35700..0000000 --- a/stats_browser.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - diff --git a/stats_node.html b/stats_node.html deleted file mode 100644 index c264c7d..0000000 --- a/stats_node.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 39edc4a4d522fe2da2f7bda7c7deb3916303fa9c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 27 Jul 2024 02:35:31 +0000 Subject: [PATCH 111/158] 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 | 207 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 178 +- SECURITY.md | 5 - benchmark/benchmark.js | 112 - benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 152 - branches.md | 56 - browser.js | 3 + browser.js.map | 1 + dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 39 - docs/types/index.d.ts | 177 - docs/types/test.ts | 45 - examples/c/Makefile | 146 - examples/c/example.c | 50 - examples/index.js | 54 - .../stdlib/ndarray/base/broadcast_shapes.h | 40 - index.js | 3 + index.js.map | 1 + lib/index.js | 45 - lib/main.js | 256 - manifest.json | 38 - package.json | 58 +- src/main.c | 118 - stats_browser.html | 4842 +++++++++++++++++ stats_node.html | 4842 +++++++++++++++++ test/dist/test.js | 33 - test/test.js | 230 - 52 files changed, 9729 insertions(+), 5336 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.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 branches.md create mode 100644 browser.js create mode 100644 browser.js.map 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/index.d.ts delete mode 100644 docs/types/test.ts delete mode 100644 examples/c/Makefile delete mode 100644 examples/c/example.c delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/broadcast_shapes.h create mode 100644 index.js create mode 100644 index.js.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 manifest.json delete mode 100644 src/main.c create mode 100644 stats_browser.html create mode 100644 stats_node.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 7f004ad..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 a07d970..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 7292af0..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: '0 12 * * 5' - - # 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 +``` -```javascript -var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); +If no recognized module system is present, access bundle contents via the global scope: + +```html + ``` #### broadcastShapes( shapes ) @@ -245,9 +251,14 @@ var sh = broadcastShapes( [ sh1, sh2 ] ); -```javascript -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); +```html + + + + + + + + ```
@@ -288,131 +304,7 @@ for ( i = 0; i < shapes.length; i++ ) { -* * * - -
- -## C APIs - - - -
- -
- - - - - -
- -### Usage - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -``` - -#### stdlib_ndarray_broadcast_shapes( M, \*\*shapes, \*ndims, \*out ) - -Broadcasts array shapes to a single shape. - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -int64_t N1 = 4; -int64_t sh1[] = { 8, 1, 6, 1 }; - -int64_t N2 = 3; -int64_t sh2[] = { 7, 1, 5 }; - -int64_t ndims[] = { N1, N2 }; -int64_t *shapes[] = { sh1, sh2 }; - -int64_t out[] = { 0, 0, 0, 0 }; -int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -if ( status != 0 ) { - // Handle error... -} -``` - -The function accepts the following arguments: - -- **M**: `[in] int64_t` number of shape arrays. -- **shapes**: `[in] int64_t**` array of shape arrays (dimensions). -- **ndims**: `[in] int64_t*` number of dimensions for each respective shape array. -- **out**: `[out] int64_t*` output shape array. - -```c -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ); -``` - -If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). - -
- - - - - -
- -### Notes - -- Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. - -
- - - - - -
- -### Examples - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main( void ) { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} -``` - -
- - - -
- 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.js b/benchmark/benchmark.js deleted file mode 100644 index 6426216..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,112 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pkg = require( './../package.json' ).name; -var broadcastShapes = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::two_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ] ], - [ [ 3, 2 ], [ 3, 1 ] ], - [ [ 1, 1 ], [ 2, 2 ] ], - [ [ 1 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::three_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::four_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ], [ 8, 1, 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ], [ 1, 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ], [ 1, 1, 2, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ], [ 1 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ], [ 5, 1, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/c/Makefile b/benchmark/c/Makefile deleted file mode 100644 index 5dc545c..0000000 --- a/benchmark/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := benchmark.out - - -# RULES # - -#/ -# Compiles C source files. -# -# @param {string} SOURCE_FILES - list of C source files -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lpthread -lblas`) -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [C_COMPILER] - C compiler -# @param {string} [CFLAGS] - C compiler flags -# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} SOURCE_FILES - list of C source files -# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {(string|void)} LIBRARIES - list of libraries (e.g., `-lpthread -lblas`) -# @param {(string|void)} LIBPATH - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} CC - C compiler -# @param {string} CFLAGS - C compiler flags -# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled benchmarks. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/benchmark/c/benchmark.c b/benchmark/c/benchmark.c deleted file mode 100644 index be62cd5..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,152 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/** -* Benchmark `broadcast_shapes`. -*/ -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "broadcast-shapes" -#define ITERATIONS 1000000 -#define REPEATS 3 - -/** -* Prints the TAP version. -*/ -void print_version() { - printf( "TAP version 13\n" ); -} - -/** -* Prints the TAP summary. -* -* @param total total number of tests -* @param passing total number of passing tests -*/ -void print_summary( int total, int passing ) { - printf( "#\n" ); - printf( "1..%d\n", total ); // TAP plan - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); -} - -/** -* Prints benchmarks results. -* -* @param elapsed elapsed time in seconds -*/ -void print_results( double elapsed ) { - double rate = (double)ITERATIONS / elapsed; - printf( " ---\n" ); - printf( " iterations: %d\n", ITERATIONS ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", rate ); - printf( " ...\n" ); -} - -/** -* Returns a clock time. -* -* @return clock time -*/ -double tic() { - struct timeval now; - gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; -} - -/** -* Generates a random double on the interval [0,1]. -* -* @return random double -*/ -double rand_double() { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark() { - double elapsed; - int8_t status; - double t; - int i; - - int64_t sh1[] = { 8, 1, 6, 1 }; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { 4, 3 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( out[ 0 ] != 8 ) { - printf( "unexpected result\n" ); - } - if ( out[ 1 ] != 7 ) { - printf( "unexpected result\n" ); - } - if ( out[ 2 ] != 6 ) { - printf( "unexpected result\n" ); - } - if ( out[ 3 ] != 5 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Main execution sequence. -*/ -int main( void ) { - double elapsed; - int i; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - for ( i = 0; i < REPEATS; i++ ) { - printf( "# c::native::%s::two_arrays\n", NAME ); - elapsed = benchmark(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", i+1 ); - } - print_summary( REPEATS, REPEATS ); -} diff --git a/branches.md b/branches.md deleted file mode 100644 index 79909c9..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes" -%% click B href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/blob/esm/README.md \ No newline at end of file diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..44a8074 --- /dev/null +++ b/browser.js @@ -0,0 +1,3 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map new file mode 100644 index 0000000..aa4b2bb --- /dev/null +++ b/browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"browser.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 87ea8b6..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import broadcastShapes from '../docs/types/index'; -export = broadcastShapes; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 625741a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var d=function(t,e){return function(){return e||t((e={exports:{}}).exports,e),e.exports}};var h=d(function(x,c){ -function g(t){var e,n,u,o,s,l,a,f,i,r,v;if(f=t.length,n=[],f===0)return n;if(o=t[0],i=o.length,f===1){for(r=0;ri&&(i=e[r]);for(r=0;r=0;){for(s=e[0]-i+r,s>=0?u=o[s]:u=1,v=1;v=0?a=t[v][l]:a=1,u===1){u=a;continue}if(!(a===1||u===a))return null}n[r]=u,r-=1}return n}c.exports=g -});var m=h();module.exports=m; -/** @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 db2949f..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = broadcastShapes;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast array shapes to a single shape.\n*\n* @module @stdlib/ndarray-base-broadcast-shapes\n*\n* @example\n* var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' );\n*\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\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,cAkLA,SAASC,EAAiBC,EAAS,CAClC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GAFAH,EAAIR,EAAO,OACXE,EAAM,CAAC,EACFM,IAAM,EACV,OAAON,EAMR,GAJAE,EAAKJ,EAAQ,CAAE,EACfS,EAAIL,EAAG,OAGFI,IAAM,EAAI,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAI,KAAME,EAAIM,CAAE,CAAE,EAEnB,OAAOR,CACR,CAGA,IADAD,EAAQ,CAAEQ,CAAE,EACNC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAM,KAAMD,EAAQU,CAAE,EAAE,MAAO,EAC1BT,EAAOS,CAAE,EAAID,IACjBA,EAAIR,EAAOS,CAAE,GAIf,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAI,KAAM,CAAE,EAIb,IADAQ,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IANAL,EAAKJ,EAAO,CAAE,EAAIQ,EAAIC,EACjBL,GAAM,EACVF,EAAMC,EAAIC,CAAG,EAEbF,EAAM,EAEDQ,EAAI,EAAGA,EAAIH,EAAGG,IAAM,CAOzB,GANAL,EAAKL,EAAOU,CAAE,EAAIF,EAAIC,EACjBJ,GAAM,EACVC,EAAIP,EAAQW,CAAE,EAAGL,CAAG,EAEpBC,EAAI,EAEAJ,IAAQ,EAAI,CAChBA,EAAMI,EACN,QACD,CACA,GAAK,EAAAA,IAAM,GAAKJ,IAAQI,GAKxB,OAAO,IACR,CACAL,EAAKQ,CAAE,EAAIP,EACXO,GAAK,CACN,CACA,OAAOR,CACR,CAKAJ,EAAO,QAAUC,ICxNjB,IAAIa,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "broadcastShapes", "shapes", "ndims", "out", "dim", "sh", "n1", "n2", "d", "M", "N", "i", "j", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f1d92f6..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,39 +0,0 @@ - -{{alias}}( shapes ) - Broadcasts array shapes to a single shape. - - Two respective dimensions in two shape arrays are compatible if - - 1. the dimensions are equal. - 2. one dimension is `1`. - - The function returns `null` if provided incompatible shapes (i.e., shapes - which cannot be broadcast with one another). - - Parameters - ---------- - shapes: Array - Array of shape arrays. - - Returns - ------- - out: Array|null - Broadcast shape. - - Examples - -------- - // Compatible shapes: - > var sh1 = [ 8, 1, 6, 1 ]; - > var sh2 = [ 7, 1, 5 ]; - > var sh = {{alias}}( [ sh1, sh2 ] ) - [ 8, 7, 6, 5 ] - - // Incompatible shapes: - > sh1 = [ 3, 2 ]; - > sh1 = [ 2, 3 ]; - > sh = {{alias}}( [ sh1, sh2 ] ) - null - - See Also - -------- - diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts deleted file mode 100644 index c2702cf..0000000 --- a/docs/types/index.d.ts +++ /dev/null @@ -1,177 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ArrayLike } from '@stdlib/types/array'; - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param shapes - array shapes -* @returns broadcast shape -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -declare function broadcastShapes( shapes: ArrayLike> ): ArrayLike; - - -// EXPORTS // - -export = broadcastShapes; diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 2886539..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 broadcastShapes = require( './index' ); - - -// TESTS // - -// The function returns an array of numbers... -{ - broadcastShapes( [ [ 1, 2 ], [ 2, 2 ] ] ); // $ExpectType ArrayLike -} - -// The compiler throws an error if the function is not provided an array-like object containing array-like objects containing numbers... -{ - broadcastShapes( '5' ); // $ExpectError - broadcastShapes( 5 ); // $ExpectError - broadcastShapes( true ); // $ExpectError - broadcastShapes( false ); // $ExpectError - broadcastShapes( null ); // $ExpectError - broadcastShapes( {} ); // $ExpectError - broadcastShapes( [ '5' ] ); // $ExpectError - broadcastShapes( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - broadcastShapes(); // $ExpectError - broadcastShapes( [ [ 1, 2, 3 ] ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/c/Makefile b/examples/c/Makefile deleted file mode 100644 index 70c91f4..0000000 --- a/examples/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := example.out - - -# RULES # - -#/ -# Compiles source files. -# -# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) -# @param {string} [CFLAGS] - C compiler options -# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) -# @param {string} [SOURCE_FILES] - list of source files -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} CC - C compiler (e.g., `gcc`) -# @param {string} CFLAGS - C compiler options -# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) -# @param {string} SOURCE_FILES - list of source files -# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) -# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled examples. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/examples/c/example.c b/examples/c/example.c deleted file mode 100644 index 4bc54d5..0000000 --- a/examples/c/example.c +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main( void ) { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 28811f9..0000000 --- a/examples/index.js +++ /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. -*/ - -'use strict'; - -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( './../lib' ); - -var shapes; -var out; -var sh; -var i; -var j; - -function shape2string( shape ) { - return lpad( shape.join( ' x ' ), 20, ' ' ); -} - -shapes = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] -]; - -for ( i = 0; i < shapes.length; i++ ) { - sh = shapes[ i ]; - for ( j = 0; j < sh.length; j++ ) { - console.log( shape2string( sh[ j ] ) ); - } - console.log( lpad( '', 20, '-' ) ); - - out = broadcastShapes( sh ); - console.log( shape2string( out )+'\n' ); -} diff --git a/include/stdlib/ndarray/base/broadcast_shapes.h b/include/stdlib/ndarray/base/broadcast_shapes.h deleted file mode 100644 index e23dce1..0000000 --- a/include/stdlib/ndarray/base/broadcast_shapes.h +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#ifndef STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H -#define STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H - -#include - -/* -* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. -*/ -#ifdef __cplusplus -extern "C" { -#endif - -/** -* Broadcasts array shapes to a single shape. -*/ -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H diff --git a/index.js b/index.js new file mode 100644 index 0000000..d225eb4 --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map new file mode 100644 index 0000000..0c02c0f --- /dev/null +++ b/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 0c9817e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Broadcast array shapes to a single shape. -* -* @module @stdlib/ndarray-base-broadcast-shapes -* -* @example -* var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); -* -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -*/ - -// 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 8558e60..0000000 --- a/lib/main.js +++ /dev/null @@ -1,256 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param {Array} shapes - array of shape arrays -* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`) -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [ 8, 0, 1, 6, 1 ], -* [ 8, 8, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -function broadcastShapes( shapes ) { - var ndims; - var out; - var dim; - var sh; - var n1; - var n2; - var d; - var M; - var N; - var i; - var j; - - M = shapes.length; - out = []; - if ( M === 0 ) { - return out; - } - sh = shapes[ 0 ]; - N = sh.length; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M === 1 ) { - // Need to manually copy to output shape, as shapes could be array-like objects... - for ( i = 0; i < N; i++ ) { - out.push( sh[ i ] ); - } - return out; - } - // Determine the maximum dimensionality... - ndims = [ N ]; - for ( i = 1; i < M; i++ ) { - ndims.push( shapes[ i ].length ); - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Initialize the output array... - for ( i = 0; i < N; i++ ) { - out.push( 0 ); - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim === 1 ) { - dim = d; - continue; - } - if ( d === 1 || dim === d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return null; - } - out[ i ] = dim; - i -= 1; - } - return out; -} - - -// EXPORTS // - -module.exports = broadcastShapes; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 890a937..0000000 --- a/manifest.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "options": {}, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [] - } - ] -} diff --git a/package.json b/package.json index 128b641..a9ff889 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,7 @@ "version": "0.2.2", "description": "Broadcast array shapes to a single shape.", "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", - "include": "./include", - "lib": "./lib", - "src": "./src", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "main": "./index.js", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,33 +12,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/types": "^0.3.2", - "@stdlib/utils-library-manifest": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/string-left-pad": "^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", "stdtypes", @@ -80,9 +27,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 35a3654..0000000 --- a/src/main.c +++ /dev/null @@ -1,118 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). -* -* - Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. -* -* @param M number of array shapes -* @param shapes pointer to an array containing shape arrays -* @param ndims array containing the number of dimensions for (i.e., length of) each respective shape array -* @param out pointer to output array -* @return status -* -* @example -* #include "stdlib/ndarray/base/broadcast_shapes.h" -* #include -* -* int64_t N1 = 4; -* int64_t sh1[] = { 8, 1, 6, 1 }; -* -* int64_t N2 = 3; -* int64_t sh2[] = { 7, 1, 5 }; -* -* int64_t ndims[] = { N1, N2 }; -* int64_t *shapes[] = { sh1, sh2 }; -* -* int64_t out[] = { 0, 0, 0, 0 }; -* int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -*/ -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ) { - int64_t dim; - int64_t *sh; - int64_t n1; - int64_t n2; - int64_t d; - int64_t N; - int64_t i; - int64_t j; - - if ( M == 0 ) { - return 0; - } - sh = shapes[ 0 ]; - N = ndims[ 0 ]; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M == 1 ) { - for ( i = 0; i < N; i++ ) { - out[ i ] = sh[ i ]; - } - return 0; - } - // Determine the maximum dimensionality... - for ( i = 1; i < M; i++ ) { - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim == 1 ) { - dim = d; - continue; - } - if ( d == 1 || dim == d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return -1; - } - out[ i ] = dim; - i -= 1; - } - return 0; -} diff --git a/stats_browser.html b/stats_browser.html new file mode 100644 index 0000000..2f35700 --- /dev/null +++ b/stats_browser.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/stats_node.html b/stats_node.html new file mode 100644 index 0000000..c264c7d --- /dev/null +++ b/stats_node.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 63f703c..0000000 --- a/test/test.js +++ /dev/null @@ -1,230 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var broadcastShapes = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastShapes, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] - ]; - - expected = [ - [ 1, 2 ], - [ 3, 4 ], - [ 5, 6, 7 ], - [ 3, 3 ], - [ 3 ], - [ 3, 2 ], - [ 2, 3 ], - [ 1, 2 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty dims)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 0 ], [ 0, 0 ] ], - [ [ 0, 1 ], [ 0, 0 ] ], - [ [ 1, 0 ], [ 0, 1 ] ], - [ [ 1, 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 1, 0 ] ], - [ [ 1, 1 ], [ 0, 1 ] ], - [ [ 0 ], [ 0, 0 ] ], - [ [ 0 ], [ 0, 1 ] ], - [ [ 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 0 ] ], - [ [ 1 ], [ 0, 1 ] ], - [ [ 1 ], [ 1, 0 ] ], - [ [ 1 ], [ 8, 0 ] ], - [ [ 8, 1, 6, 1 ], [ 0, 1, 5 ] ], - [ [ 8, 0, 6, 1 ], [ 1, 5 ] ] - ]; - - expected = [ - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 1, 0 ], - [ 8, 0 ], - [ 8, 0, 6, 5 ], - [ 8, 0, 6, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (no shapes)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [] - ]; - - expected = [ - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty shapes (i.e., zero-dimensional array broadcasting))', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [] ], - [ [], [] ], - [ [], [], [] ], - [ [], [ 0 ] ], - [ [ 0 ], [] ], - [ [], [ 0, 0 ] ], - [ [ 0, 0 ], [] ], - [ [], [ 1, 0 ] ], - [ [], [ 0, 1 ] ], - [ [], [ 3, 3 ] ], - [ [], [ 3, 3 ], [] ] - ]; - - expected = [ - [], - [], - [], - [ 0 ], - [ 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 3, 3 ], - [ 3, 3 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (single shape)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 7 ] ], - [ [ 1, 1 ] ], - [ [ 5, 6, 1 ] ] - ]; - - expected = [ - [ 7 ], - [ 1, 1 ], - [ 5, 6, 1 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function returns `null` if provided incompatible shapes', function test( t ) { - var actual; - var values; - var i; - - values = [ - [ [ 3 ], [ 4 ] ], - [ [ 2, 3 ], [ 2 ] ], - [ [ 3 ], [ 3 ], [ 4 ] ], - [ [ 1, 3, 4 ], [ 2, 3, 3 ] ], - [ [ 1, 2 ], [ 3, 1 ], [ 3, 2 ], [ 10, 5 ] ], - [ [ 2 ], [ 2, 3 ] ], - [ [ 2 ], [ 2 ], [ 2 ], [ 2 ], [ 3 ], [ 3 ], [ 3 ], [ 3 ] ], - [ [ 9, 0, 9 ], [ 0, 9, 0 ] ], - [ [ 9, 9, 9 ], [ 0, 9, 9 ] ], - [ [ 9, 0, 9 ], [ 9, 9, 9 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 0 ] ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.strictEqual( actual, null, 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); From 3d5b9ceac715490f22983207f85052dc4a6ad39b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 27 Jul 2024 02:51:25 +0000 Subject: [PATCH 112/158] Update README.md for UMD bundle v0.2.2 --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 4cf6bff..e0778ad 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ limitations under the License. To use in Observable, ```javascript -broadcastShapes = require( 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-shapes@umd/browser.js' ) +broadcastShapes = require( 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-shapes@v0.2.2-umd/browser.js' ) ``` To vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build: @@ -66,7 +66,7 @@ var broadcastShapes = require( 'path/to/vendor/umd/ndarray-base-broadcast-shapes To include the bundle in a webpage, ```html - + ``` If no recognized module system is present, access bundle contents via the global scope: @@ -256,7 +256,7 @@ var sh = broadcastShapes( [ sh1, sh2 ] ); - + + ``` If no recognized module system is present, access bundle contents via the global scope: @@ -256,7 +261,7 @@ var sh = broadcastShapes( [ sh1, sh2 ] ); - + - - - - diff --git a/stats_node.html b/stats_node.html deleted file mode 100644 index c264c7d..0000000 --- a/stats_node.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From f2db1f78f71b950944fefcda03615fefd8f345b9 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Aug 2024 03:48:51 +0000 Subject: [PATCH 116/158] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 168 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 178 +- SECURITY.md | 5 - benchmark/benchmark.js | 112 - benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 149 - branches.md | 56 - browser.js | 3 + browser.js.map | 1 + dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 39 - docs/types/index.d.ts | 177 - docs/types/test.ts | 45 - examples/c/Makefile | 146 - examples/c/example.c | 50 - examples/index.js | 54 - .../stdlib/ndarray/base/broadcast_shapes.h | 40 - index.js | 3 + index.js.map | 1 + lib/index.js | 45 - lib/main.js | 256 - manifest.json | 38 - package.json | 58 +- src/main.c | 118 - stats_browser.html | 4842 +++++++++++++++++ stats_node.html | 4842 +++++++++++++++++ test/dist/test.js | 33 - test/test.js | 230 - 53 files changed, 9729 insertions(+), 5297 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.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 branches.md create mode 100644 browser.js create mode 100644 browser.js.map 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/index.d.ts delete mode 100644 docs/types/test.ts delete mode 100644 examples/c/Makefile delete mode 100644 examples/c/example.c delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/broadcast_shapes.h create mode 100644 index.js create mode 100644 index.js.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 manifest.json delete mode 100644 src/main.c create mode 100644 stats_browser.html create mode 100644 stats_node.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/.keepalive b/.github/.keepalive deleted file mode 100644 index 016f235..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-08-01T01:29:52.003Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 7f004ad..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 a07d970..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 7292af0..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: '0 12 * * 5' - - # 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 +``` -```javascript -var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); +If no recognized module system is present, access bundle contents via the global scope: + +```html + ``` #### broadcastShapes( shapes ) @@ -245,9 +251,14 @@ var sh = broadcastShapes( [ sh1, sh2 ] ); -```javascript -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); +```html + + + + + + + + ```
@@ -288,131 +304,7 @@ for ( i = 0; i < shapes.length; i++ ) { -* * * - -
- -## C APIs - - - -
- -
- - - - - -
- -### Usage - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -``` - -#### stdlib_ndarray_broadcast_shapes( M, \*\*shapes, \*ndims, \*out ) - -Broadcasts array shapes to a single shape. - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -int64_t N1 = 4; -int64_t sh1[] = { 8, 1, 6, 1 }; - -int64_t N2 = 3; -int64_t sh2[] = { 7, 1, 5 }; - -int64_t ndims[] = { N1, N2 }; -int64_t *shapes[] = { sh1, sh2 }; - -int64_t out[] = { 0, 0, 0, 0 }; -int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -if ( status != 0 ) { - // Handle error... -} -``` - -The function accepts the following arguments: - -- **M**: `[in] int64_t` number of shape arrays. -- **shapes**: `[in] int64_t**` array of shape arrays (dimensions). -- **ndims**: `[in] int64_t*` number of dimensions for each respective shape array. -- **out**: `[out] int64_t*` output shape array. - -```c -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ); -``` - -If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). - -
- - - - - -
- -### Notes - -- Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. - -
- - - - - -
- -### Examples - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main( void ) { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} -``` - -
- - - -
- 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.js b/benchmark/benchmark.js deleted file mode 100644 index 6426216..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,112 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pkg = require( './../package.json' ).name; -var broadcastShapes = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::two_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ] ], - [ [ 3, 2 ], [ 3, 1 ] ], - [ [ 1, 1 ], [ 2, 2 ] ], - [ [ 1 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::three_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::four_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ], [ 8, 1, 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ], [ 1, 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ], [ 1, 1, 2, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ], [ 1 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ], [ 5, 1, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/c/Makefile b/benchmark/c/Makefile deleted file mode 100644 index 5dc545c..0000000 --- a/benchmark/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := benchmark.out - - -# RULES # - -#/ -# Compiles C source files. -# -# @param {string} SOURCE_FILES - list of C source files -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lpthread -lblas`) -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [C_COMPILER] - C compiler -# @param {string} [CFLAGS] - C compiler flags -# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} SOURCE_FILES - list of C source files -# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {(string|void)} LIBRARIES - list of libraries (e.g., `-lpthread -lblas`) -# @param {(string|void)} LIBPATH - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} CC - C compiler -# @param {string} CFLAGS - C compiler flags -# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled benchmarks. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/benchmark/c/benchmark.c b/benchmark/c/benchmark.c deleted file mode 100644 index 82d2be5..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,149 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "broadcast-shapes" -#define ITERATIONS 1000000 -#define REPEATS 3 - -/** -* Prints the TAP version. -*/ -static void print_version( void ) { - printf( "TAP version 13\n" ); -} - -/** -* Prints the TAP summary. -* -* @param total total number of tests -* @param passing total number of passing tests -*/ -static void print_summary( int total, int passing ) { - printf( "#\n" ); - printf( "1..%d\n", total ); // TAP plan - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); -} - -/** -* Prints benchmarks results. -* -* @param elapsed elapsed time in seconds -*/ -static void print_results( double elapsed ) { - double rate = (double)ITERATIONS / elapsed; - printf( " ---\n" ); - printf( " iterations: %d\n", ITERATIONS ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", rate ); - printf( " ...\n" ); -} - -/** -* Returns a clock time. -* -* @return clock time -*/ -static double tic( void ) { - struct timeval now; - gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; -} - -/** -* Generates a random number on the interval [0,1). -* -* @return random number -*/ -static double rand_double( void ) { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark( void ) { - double elapsed; - int8_t status; - double t; - int i; - - const int64_t sh1[] = { 8, 1, 6, 1 }; - const int64_t sh2[] = { 7, 1, 5 }; - - const int64_t ndims[] = { 4, 3 }; - const int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( out[ 0 ] != 8 ) { - printf( "unexpected result\n" ); - } - if ( out[ 1 ] != 7 ) { - printf( "unexpected result\n" ); - } - if ( out[ 2 ] != 6 ) { - printf( "unexpected result\n" ); - } - if ( out[ 3 ] != 5 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Main execution sequence. -*/ -int main( void ) { - double elapsed; - int i; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - for ( i = 0; i < REPEATS; i++ ) { - printf( "# c::native::%s::two_arrays\n", NAME ); - elapsed = benchmark(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", i+1 ); - } - print_summary( REPEATS, REPEATS ); -} diff --git a/branches.md b/branches.md deleted file mode 100644 index 79909c9..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes" -%% click B href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/blob/esm/README.md \ No newline at end of file diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..44a8074 --- /dev/null +++ b/browser.js @@ -0,0 +1,3 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map new file mode 100644 index 0000000..aa4b2bb --- /dev/null +++ b/browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"browser.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 87ea8b6..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import broadcastShapes from '../docs/types/index'; -export = broadcastShapes; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 625741a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var d=function(t,e){return function(){return e||t((e={exports:{}}).exports,e),e.exports}};var h=d(function(x,c){ -function g(t){var e,n,u,o,s,l,a,f,i,r,v;if(f=t.length,n=[],f===0)return n;if(o=t[0],i=o.length,f===1){for(r=0;ri&&(i=e[r]);for(r=0;r=0;){for(s=e[0]-i+r,s>=0?u=o[s]:u=1,v=1;v=0?a=t[v][l]:a=1,u===1){u=a;continue}if(!(a===1||u===a))return null}n[r]=u,r-=1}return n}c.exports=g -});var m=h();module.exports=m; -/** @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 db2949f..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = broadcastShapes;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast array shapes to a single shape.\n*\n* @module @stdlib/ndarray-base-broadcast-shapes\n*\n* @example\n* var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' );\n*\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\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,cAkLA,SAASC,EAAiBC,EAAS,CAClC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GAFAH,EAAIR,EAAO,OACXE,EAAM,CAAC,EACFM,IAAM,EACV,OAAON,EAMR,GAJAE,EAAKJ,EAAQ,CAAE,EACfS,EAAIL,EAAG,OAGFI,IAAM,EAAI,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAI,KAAME,EAAIM,CAAE,CAAE,EAEnB,OAAOR,CACR,CAGA,IADAD,EAAQ,CAAEQ,CAAE,EACNC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAM,KAAMD,EAAQU,CAAE,EAAE,MAAO,EAC1BT,EAAOS,CAAE,EAAID,IACjBA,EAAIR,EAAOS,CAAE,GAIf,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAI,KAAM,CAAE,EAIb,IADAQ,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IANAL,EAAKJ,EAAO,CAAE,EAAIQ,EAAIC,EACjBL,GAAM,EACVF,EAAMC,EAAIC,CAAG,EAEbF,EAAM,EAEDQ,EAAI,EAAGA,EAAIH,EAAGG,IAAM,CAOzB,GANAL,EAAKL,EAAOU,CAAE,EAAIF,EAAIC,EACjBJ,GAAM,EACVC,EAAIP,EAAQW,CAAE,EAAGL,CAAG,EAEpBC,EAAI,EAEAJ,IAAQ,EAAI,CAChBA,EAAMI,EACN,QACD,CACA,GAAK,EAAAA,IAAM,GAAKJ,IAAQI,GAKxB,OAAO,IACR,CACAL,EAAKQ,CAAE,EAAIP,EACXO,GAAK,CACN,CACA,OAAOR,CACR,CAKAJ,EAAO,QAAUC,ICxNjB,IAAIa,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "broadcastShapes", "shapes", "ndims", "out", "dim", "sh", "n1", "n2", "d", "M", "N", "i", "j", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f1d92f6..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,39 +0,0 @@ - -{{alias}}( shapes ) - Broadcasts array shapes to a single shape. - - Two respective dimensions in two shape arrays are compatible if - - 1. the dimensions are equal. - 2. one dimension is `1`. - - The function returns `null` if provided incompatible shapes (i.e., shapes - which cannot be broadcast with one another). - - Parameters - ---------- - shapes: Array - Array of shape arrays. - - Returns - ------- - out: Array|null - Broadcast shape. - - Examples - -------- - // Compatible shapes: - > var sh1 = [ 8, 1, 6, 1 ]; - > var sh2 = [ 7, 1, 5 ]; - > var sh = {{alias}}( [ sh1, sh2 ] ) - [ 8, 7, 6, 5 ] - - // Incompatible shapes: - > sh1 = [ 3, 2 ]; - > sh1 = [ 2, 3 ]; - > sh = {{alias}}( [ sh1, sh2 ] ) - null - - See Also - -------- - diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts deleted file mode 100644 index c2702cf..0000000 --- a/docs/types/index.d.ts +++ /dev/null @@ -1,177 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ArrayLike } from '@stdlib/types/array'; - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param shapes - array shapes -* @returns broadcast shape -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -declare function broadcastShapes( shapes: ArrayLike> ): ArrayLike; - - -// EXPORTS // - -export = broadcastShapes; diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 2886539..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 broadcastShapes = require( './index' ); - - -// TESTS // - -// The function returns an array of numbers... -{ - broadcastShapes( [ [ 1, 2 ], [ 2, 2 ] ] ); // $ExpectType ArrayLike -} - -// The compiler throws an error if the function is not provided an array-like object containing array-like objects containing numbers... -{ - broadcastShapes( '5' ); // $ExpectError - broadcastShapes( 5 ); // $ExpectError - broadcastShapes( true ); // $ExpectError - broadcastShapes( false ); // $ExpectError - broadcastShapes( null ); // $ExpectError - broadcastShapes( {} ); // $ExpectError - broadcastShapes( [ '5' ] ); // $ExpectError - broadcastShapes( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - broadcastShapes(); // $ExpectError - broadcastShapes( [ [ 1, 2, 3 ] ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/c/Makefile b/examples/c/Makefile deleted file mode 100644 index 70c91f4..0000000 --- a/examples/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := example.out - - -# RULES # - -#/ -# Compiles source files. -# -# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) -# @param {string} [CFLAGS] - C compiler options -# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) -# @param {string} [SOURCE_FILES] - list of source files -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} CC - C compiler (e.g., `gcc`) -# @param {string} CFLAGS - C compiler options -# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) -# @param {string} SOURCE_FILES - list of source files -# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) -# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled examples. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/examples/c/example.c b/examples/c/example.c deleted file mode 100644 index 4bc54d5..0000000 --- a/examples/c/example.c +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main( void ) { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 28811f9..0000000 --- a/examples/index.js +++ /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. -*/ - -'use strict'; - -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( './../lib' ); - -var shapes; -var out; -var sh; -var i; -var j; - -function shape2string( shape ) { - return lpad( shape.join( ' x ' ), 20, ' ' ); -} - -shapes = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] -]; - -for ( i = 0; i < shapes.length; i++ ) { - sh = shapes[ i ]; - for ( j = 0; j < sh.length; j++ ) { - console.log( shape2string( sh[ j ] ) ); - } - console.log( lpad( '', 20, '-' ) ); - - out = broadcastShapes( sh ); - console.log( shape2string( out )+'\n' ); -} diff --git a/include/stdlib/ndarray/base/broadcast_shapes.h b/include/stdlib/ndarray/base/broadcast_shapes.h deleted file mode 100644 index e23dce1..0000000 --- a/include/stdlib/ndarray/base/broadcast_shapes.h +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#ifndef STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H -#define STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H - -#include - -/* -* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. -*/ -#ifdef __cplusplus -extern "C" { -#endif - -/** -* Broadcasts array shapes to a single shape. -*/ -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H diff --git a/index.js b/index.js new file mode 100644 index 0000000..d225eb4 --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map new file mode 100644 index 0000000..0c02c0f --- /dev/null +++ b/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 0c9817e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Broadcast array shapes to a single shape. -* -* @module @stdlib/ndarray-base-broadcast-shapes -* -* @example -* var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); -* -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -*/ - -// 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 8558e60..0000000 --- a/lib/main.js +++ /dev/null @@ -1,256 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param {Array} shapes - array of shape arrays -* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`) -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [ 8, 0, 1, 6, 1 ], -* [ 8, 8, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -function broadcastShapes( shapes ) { - var ndims; - var out; - var dim; - var sh; - var n1; - var n2; - var d; - var M; - var N; - var i; - var j; - - M = shapes.length; - out = []; - if ( M === 0 ) { - return out; - } - sh = shapes[ 0 ]; - N = sh.length; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M === 1 ) { - // Need to manually copy to output shape, as shapes could be array-like objects... - for ( i = 0; i < N; i++ ) { - out.push( sh[ i ] ); - } - return out; - } - // Determine the maximum dimensionality... - ndims = [ N ]; - for ( i = 1; i < M; i++ ) { - ndims.push( shapes[ i ].length ); - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Initialize the output array... - for ( i = 0; i < N; i++ ) { - out.push( 0 ); - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim === 1 ) { - dim = d; - continue; - } - if ( d === 1 || dim === d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return null; - } - out[ i ] = dim; - i -= 1; - } - return out; -} - - -// EXPORTS // - -module.exports = broadcastShapes; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 890a937..0000000 --- a/manifest.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "options": {}, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [] - } - ] -} diff --git a/package.json b/package.json index 8e3322c..a9ff889 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,7 @@ "version": "0.2.2", "description": "Broadcast array shapes to a single shape.", "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", - "include": "./include", - "lib": "./lib", - "src": "./src", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "main": "./index.js", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,33 +12,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/types": "^0.3.2", - "@stdlib/utils-library-manifest": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/string-left-pad": "^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", "stdtypes", @@ -80,9 +27,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 35a3654..0000000 --- a/src/main.c +++ /dev/null @@ -1,118 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). -* -* - Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. -* -* @param M number of array shapes -* @param shapes pointer to an array containing shape arrays -* @param ndims array containing the number of dimensions for (i.e., length of) each respective shape array -* @param out pointer to output array -* @return status -* -* @example -* #include "stdlib/ndarray/base/broadcast_shapes.h" -* #include -* -* int64_t N1 = 4; -* int64_t sh1[] = { 8, 1, 6, 1 }; -* -* int64_t N2 = 3; -* int64_t sh2[] = { 7, 1, 5 }; -* -* int64_t ndims[] = { N1, N2 }; -* int64_t *shapes[] = { sh1, sh2 }; -* -* int64_t out[] = { 0, 0, 0, 0 }; -* int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -*/ -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ) { - int64_t dim; - int64_t *sh; - int64_t n1; - int64_t n2; - int64_t d; - int64_t N; - int64_t i; - int64_t j; - - if ( M == 0 ) { - return 0; - } - sh = shapes[ 0 ]; - N = ndims[ 0 ]; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M == 1 ) { - for ( i = 0; i < N; i++ ) { - out[ i ] = sh[ i ]; - } - return 0; - } - // Determine the maximum dimensionality... - for ( i = 1; i < M; i++ ) { - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim == 1 ) { - dim = d; - continue; - } - if ( d == 1 || dim == d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return -1; - } - out[ i ] = dim; - i -= 1; - } - return 0; -} diff --git a/stats_browser.html b/stats_browser.html new file mode 100644 index 0000000..2f35700 --- /dev/null +++ b/stats_browser.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/stats_node.html b/stats_node.html new file mode 100644 index 0000000..c264c7d --- /dev/null +++ b/stats_node.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 63f703c..0000000 --- a/test/test.js +++ /dev/null @@ -1,230 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var broadcastShapes = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastShapes, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] - ]; - - expected = [ - [ 1, 2 ], - [ 3, 4 ], - [ 5, 6, 7 ], - [ 3, 3 ], - [ 3 ], - [ 3, 2 ], - [ 2, 3 ], - [ 1, 2 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty dims)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 0 ], [ 0, 0 ] ], - [ [ 0, 1 ], [ 0, 0 ] ], - [ [ 1, 0 ], [ 0, 1 ] ], - [ [ 1, 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 1, 0 ] ], - [ [ 1, 1 ], [ 0, 1 ] ], - [ [ 0 ], [ 0, 0 ] ], - [ [ 0 ], [ 0, 1 ] ], - [ [ 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 0 ] ], - [ [ 1 ], [ 0, 1 ] ], - [ [ 1 ], [ 1, 0 ] ], - [ [ 1 ], [ 8, 0 ] ], - [ [ 8, 1, 6, 1 ], [ 0, 1, 5 ] ], - [ [ 8, 0, 6, 1 ], [ 1, 5 ] ] - ]; - - expected = [ - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 1, 0 ], - [ 8, 0 ], - [ 8, 0, 6, 5 ], - [ 8, 0, 6, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (no shapes)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [] - ]; - - expected = [ - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty shapes (i.e., zero-dimensional array broadcasting))', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [] ], - [ [], [] ], - [ [], [], [] ], - [ [], [ 0 ] ], - [ [ 0 ], [] ], - [ [], [ 0, 0 ] ], - [ [ 0, 0 ], [] ], - [ [], [ 1, 0 ] ], - [ [], [ 0, 1 ] ], - [ [], [ 3, 3 ] ], - [ [], [ 3, 3 ], [] ] - ]; - - expected = [ - [], - [], - [], - [ 0 ], - [ 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 3, 3 ], - [ 3, 3 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (single shape)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 7 ] ], - [ [ 1, 1 ] ], - [ [ 5, 6, 1 ] ] - ]; - - expected = [ - [ 7 ], - [ 1, 1 ], - [ 5, 6, 1 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function returns `null` if provided incompatible shapes', function test( t ) { - var actual; - var values; - var i; - - values = [ - [ [ 3 ], [ 4 ] ], - [ [ 2, 3 ], [ 2 ] ], - [ [ 3 ], [ 3 ], [ 4 ] ], - [ [ 1, 3, 4 ], [ 2, 3, 3 ] ], - [ [ 1, 2 ], [ 3, 1 ], [ 3, 2 ], [ 10, 5 ] ], - [ [ 2 ], [ 2, 3 ] ], - [ [ 2 ], [ 2 ], [ 2 ], [ 2 ], [ 3 ], [ 3 ], [ 3 ], [ 3 ] ], - [ [ 9, 0, 9 ], [ 0, 9, 0 ] ], - [ [ 9, 9, 9 ], [ 0, 9, 9 ] ], - [ [ 9, 0, 9 ], [ 9, 9, 9 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 0 ] ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.strictEqual( actual, null, 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); From d292dad37154da6c72b557a8679a4cfd34c7b25f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 3 Aug 2024 16:38:01 +0000 Subject: [PATCH 117/158] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 4e32d89..8e3322c 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,8 @@ }, "dependencies": { "@stdlib/types": "^0.3.2", - "@stdlib/utils-library-manifest": "^0.2.2" + "@stdlib/utils-library-manifest": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, "devDependencies": { "@stdlib/string-left-pad": "^0.2.2", @@ -84,4 +85,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From 3dbea8acc8f380c9c6636993eec7497a28092cc6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 3 Aug 2024 17:43:29 +0000 Subject: [PATCH 118/158] Remove files --- browser.js | 3 - browser.js.map | 1 - index.js | 3 - index.js.map | 1 - stats_browser.html | 4842 -------------------------------------------- stats_node.html | 4842 -------------------------------------------- 6 files changed, 9692 deletions(-) delete mode 100644 browser.js delete mode 100644 browser.js.map delete mode 100644 index.js delete mode 100644 index.js.map delete mode 100644 stats_browser.html delete mode 100644 stats_node.html diff --git a/browser.js b/browser.js deleted file mode 100644 index 44a8074..0000000 --- a/browser.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); -//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map deleted file mode 100644 index aa4b2bb..0000000 --- a/browser.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"browser.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/index.js b/index.js deleted file mode 100644 index d225eb4..0000000 --- a/index.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); -//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map deleted file mode 100644 index 0c02c0f..0000000 --- a/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/stats_browser.html b/stats_browser.html deleted file mode 100644 index 2f35700..0000000 --- a/stats_browser.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - diff --git a/stats_node.html b/stats_node.html deleted file mode 100644 index c264c7d..0000000 --- a/stats_node.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 6300f7a429047306b86a3848fa5656370a766fa9 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 3 Aug 2024 17:43:42 +0000 Subject: [PATCH 119/158] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 241 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 178 +- SECURITY.md | 5 - benchmark/benchmark.js | 112 - benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 149 - branches.md | 56 - browser.js | 3 + browser.js.map | 1 + dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 39 - docs/types/index.d.ts | 177 - docs/types/test.ts | 45 - examples/c/Makefile | 146 - examples/c/example.c | 50 - examples/index.js | 54 - .../stdlib/ndarray/base/broadcast_shapes.h | 40 - index.js | 3 + index.js.map | 1 + lib/index.js | 45 - lib/main.js | 256 - manifest.json | 38 - package.json | 58 +- src/main.c | 118 - stats_browser.html | 4842 +++++++++++++++++ stats_node.html | 4842 +++++++++++++++++ test/dist/test.js | 33 - test/test.js | 230 - 53 files changed, 9729 insertions(+), 5370 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.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 branches.md create mode 100644 browser.js create mode 100644 browser.js.map 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/index.d.ts delete mode 100644 docs/types/test.ts delete mode 100644 examples/c/Makefile delete mode 100644 examples/c/example.c delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/broadcast_shapes.h create mode 100644 index.js create mode 100644 index.js.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 manifest.json delete mode 100644 src/main.c create mode 100644 stats_browser.html create mode 100644 stats_node.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/.keepalive b/.github/.keepalive deleted file mode 100644 index ab74c16..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-08-03T16:16:24.358Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 7f004ad..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 a07d970..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 7292af0..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: '0 12 * * 5' - - # 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 +``` -```javascript -var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); +If no recognized module system is present, access bundle contents via the global scope: + +```html + ``` #### broadcastShapes( shapes ) @@ -245,9 +251,14 @@ var sh = broadcastShapes( [ sh1, sh2 ] ); -```javascript -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); +```html + + + + + + + + ```
@@ -288,131 +304,7 @@ for ( i = 0; i < shapes.length; i++ ) { -* * * - -
- -## C APIs - - - -
- -
- - - - - -
- -### Usage - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -``` - -#### stdlib_ndarray_broadcast_shapes( M, \*\*shapes, \*ndims, \*out ) - -Broadcasts array shapes to a single shape. - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -int64_t N1 = 4; -int64_t sh1[] = { 8, 1, 6, 1 }; - -int64_t N2 = 3; -int64_t sh2[] = { 7, 1, 5 }; - -int64_t ndims[] = { N1, N2 }; -int64_t *shapes[] = { sh1, sh2 }; - -int64_t out[] = { 0, 0, 0, 0 }; -int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -if ( status != 0 ) { - // Handle error... -} -``` - -The function accepts the following arguments: - -- **M**: `[in] int64_t` number of shape arrays. -- **shapes**: `[in] int64_t**` array of shape arrays (dimensions). -- **ndims**: `[in] int64_t*` number of dimensions for each respective shape array. -- **out**: `[out] int64_t*` output shape array. - -```c -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ); -``` - -If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). - -
- - - - - -
- -### Notes - -- Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. - -
- - - - - -
- -### Examples - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main( void ) { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} -``` - -
- - - -
- 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.js b/benchmark/benchmark.js deleted file mode 100644 index 6426216..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,112 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pkg = require( './../package.json' ).name; -var broadcastShapes = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::two_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ] ], - [ [ 3, 2 ], [ 3, 1 ] ], - [ [ 1, 1 ], [ 2, 2 ] ], - [ [ 1 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::three_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::four_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ], [ 8, 1, 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ], [ 1, 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ], [ 1, 1, 2, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ], [ 1 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ], [ 5, 1, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/c/Makefile b/benchmark/c/Makefile deleted file mode 100644 index 5dc545c..0000000 --- a/benchmark/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := benchmark.out - - -# RULES # - -#/ -# Compiles C source files. -# -# @param {string} SOURCE_FILES - list of C source files -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lpthread -lblas`) -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [C_COMPILER] - C compiler -# @param {string} [CFLAGS] - C compiler flags -# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} SOURCE_FILES - list of C source files -# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {(string|void)} LIBRARIES - list of libraries (e.g., `-lpthread -lblas`) -# @param {(string|void)} LIBPATH - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} CC - C compiler -# @param {string} CFLAGS - C compiler flags -# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled benchmarks. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/benchmark/c/benchmark.c b/benchmark/c/benchmark.c deleted file mode 100644 index 82d2be5..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,149 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "broadcast-shapes" -#define ITERATIONS 1000000 -#define REPEATS 3 - -/** -* Prints the TAP version. -*/ -static void print_version( void ) { - printf( "TAP version 13\n" ); -} - -/** -* Prints the TAP summary. -* -* @param total total number of tests -* @param passing total number of passing tests -*/ -static void print_summary( int total, int passing ) { - printf( "#\n" ); - printf( "1..%d\n", total ); // TAP plan - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); -} - -/** -* Prints benchmarks results. -* -* @param elapsed elapsed time in seconds -*/ -static void print_results( double elapsed ) { - double rate = (double)ITERATIONS / elapsed; - printf( " ---\n" ); - printf( " iterations: %d\n", ITERATIONS ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", rate ); - printf( " ...\n" ); -} - -/** -* Returns a clock time. -* -* @return clock time -*/ -static double tic( void ) { - struct timeval now; - gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; -} - -/** -* Generates a random number on the interval [0,1). -* -* @return random number -*/ -static double rand_double( void ) { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark( void ) { - double elapsed; - int8_t status; - double t; - int i; - - const int64_t sh1[] = { 8, 1, 6, 1 }; - const int64_t sh2[] = { 7, 1, 5 }; - - const int64_t ndims[] = { 4, 3 }; - const int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( out[ 0 ] != 8 ) { - printf( "unexpected result\n" ); - } - if ( out[ 1 ] != 7 ) { - printf( "unexpected result\n" ); - } - if ( out[ 2 ] != 6 ) { - printf( "unexpected result\n" ); - } - if ( out[ 3 ] != 5 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Main execution sequence. -*/ -int main( void ) { - double elapsed; - int i; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - for ( i = 0; i < REPEATS; i++ ) { - printf( "# c::native::%s::two_arrays\n", NAME ); - elapsed = benchmark(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", i+1 ); - } - print_summary( REPEATS, REPEATS ); -} diff --git a/branches.md b/branches.md deleted file mode 100644 index 79909c9..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes" -%% click B href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/blob/esm/README.md \ No newline at end of file diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..44a8074 --- /dev/null +++ b/browser.js @@ -0,0 +1,3 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map new file mode 100644 index 0000000..aa4b2bb --- /dev/null +++ b/browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"browser.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 87ea8b6..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import broadcastShapes from '../docs/types/index'; -export = broadcastShapes; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 625741a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var d=function(t,e){return function(){return e||t((e={exports:{}}).exports,e),e.exports}};var h=d(function(x,c){ -function g(t){var e,n,u,o,s,l,a,f,i,r,v;if(f=t.length,n=[],f===0)return n;if(o=t[0],i=o.length,f===1){for(r=0;ri&&(i=e[r]);for(r=0;r=0;){for(s=e[0]-i+r,s>=0?u=o[s]:u=1,v=1;v=0?a=t[v][l]:a=1,u===1){u=a;continue}if(!(a===1||u===a))return null}n[r]=u,r-=1}return n}c.exports=g -});var m=h();module.exports=m; -/** @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 db2949f..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = broadcastShapes;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast array shapes to a single shape.\n*\n* @module @stdlib/ndarray-base-broadcast-shapes\n*\n* @example\n* var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' );\n*\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\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,cAkLA,SAASC,EAAiBC,EAAS,CAClC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GAFAH,EAAIR,EAAO,OACXE,EAAM,CAAC,EACFM,IAAM,EACV,OAAON,EAMR,GAJAE,EAAKJ,EAAQ,CAAE,EACfS,EAAIL,EAAG,OAGFI,IAAM,EAAI,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAI,KAAME,EAAIM,CAAE,CAAE,EAEnB,OAAOR,CACR,CAGA,IADAD,EAAQ,CAAEQ,CAAE,EACNC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAM,KAAMD,EAAQU,CAAE,EAAE,MAAO,EAC1BT,EAAOS,CAAE,EAAID,IACjBA,EAAIR,EAAOS,CAAE,GAIf,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAI,KAAM,CAAE,EAIb,IADAQ,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IANAL,EAAKJ,EAAO,CAAE,EAAIQ,EAAIC,EACjBL,GAAM,EACVF,EAAMC,EAAIC,CAAG,EAEbF,EAAM,EAEDQ,EAAI,EAAGA,EAAIH,EAAGG,IAAM,CAOzB,GANAL,EAAKL,EAAOU,CAAE,EAAIF,EAAIC,EACjBJ,GAAM,EACVC,EAAIP,EAAQW,CAAE,EAAGL,CAAG,EAEpBC,EAAI,EAEAJ,IAAQ,EAAI,CAChBA,EAAMI,EACN,QACD,CACA,GAAK,EAAAA,IAAM,GAAKJ,IAAQI,GAKxB,OAAO,IACR,CACAL,EAAKQ,CAAE,EAAIP,EACXO,GAAK,CACN,CACA,OAAOR,CACR,CAKAJ,EAAO,QAAUC,ICxNjB,IAAIa,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "broadcastShapes", "shapes", "ndims", "out", "dim", "sh", "n1", "n2", "d", "M", "N", "i", "j", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f1d92f6..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,39 +0,0 @@ - -{{alias}}( shapes ) - Broadcasts array shapes to a single shape. - - Two respective dimensions in two shape arrays are compatible if - - 1. the dimensions are equal. - 2. one dimension is `1`. - - The function returns `null` if provided incompatible shapes (i.e., shapes - which cannot be broadcast with one another). - - Parameters - ---------- - shapes: Array - Array of shape arrays. - - Returns - ------- - out: Array|null - Broadcast shape. - - Examples - -------- - // Compatible shapes: - > var sh1 = [ 8, 1, 6, 1 ]; - > var sh2 = [ 7, 1, 5 ]; - > var sh = {{alias}}( [ sh1, sh2 ] ) - [ 8, 7, 6, 5 ] - - // Incompatible shapes: - > sh1 = [ 3, 2 ]; - > sh1 = [ 2, 3 ]; - > sh = {{alias}}( [ sh1, sh2 ] ) - null - - See Also - -------- - diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts deleted file mode 100644 index c2702cf..0000000 --- a/docs/types/index.d.ts +++ /dev/null @@ -1,177 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ArrayLike } from '@stdlib/types/array'; - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param shapes - array shapes -* @returns broadcast shape -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -declare function broadcastShapes( shapes: ArrayLike> ): ArrayLike; - - -// EXPORTS // - -export = broadcastShapes; diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 2886539..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 broadcastShapes = require( './index' ); - - -// TESTS // - -// The function returns an array of numbers... -{ - broadcastShapes( [ [ 1, 2 ], [ 2, 2 ] ] ); // $ExpectType ArrayLike -} - -// The compiler throws an error if the function is not provided an array-like object containing array-like objects containing numbers... -{ - broadcastShapes( '5' ); // $ExpectError - broadcastShapes( 5 ); // $ExpectError - broadcastShapes( true ); // $ExpectError - broadcastShapes( false ); // $ExpectError - broadcastShapes( null ); // $ExpectError - broadcastShapes( {} ); // $ExpectError - broadcastShapes( [ '5' ] ); // $ExpectError - broadcastShapes( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - broadcastShapes(); // $ExpectError - broadcastShapes( [ [ 1, 2, 3 ] ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/c/Makefile b/examples/c/Makefile deleted file mode 100644 index 70c91f4..0000000 --- a/examples/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := example.out - - -# RULES # - -#/ -# Compiles source files. -# -# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) -# @param {string} [CFLAGS] - C compiler options -# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) -# @param {string} [SOURCE_FILES] - list of source files -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} CC - C compiler (e.g., `gcc`) -# @param {string} CFLAGS - C compiler options -# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) -# @param {string} SOURCE_FILES - list of source files -# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) -# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled examples. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/examples/c/example.c b/examples/c/example.c deleted file mode 100644 index 4bc54d5..0000000 --- a/examples/c/example.c +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main( void ) { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 28811f9..0000000 --- a/examples/index.js +++ /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. -*/ - -'use strict'; - -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( './../lib' ); - -var shapes; -var out; -var sh; -var i; -var j; - -function shape2string( shape ) { - return lpad( shape.join( ' x ' ), 20, ' ' ); -} - -shapes = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] -]; - -for ( i = 0; i < shapes.length; i++ ) { - sh = shapes[ i ]; - for ( j = 0; j < sh.length; j++ ) { - console.log( shape2string( sh[ j ] ) ); - } - console.log( lpad( '', 20, '-' ) ); - - out = broadcastShapes( sh ); - console.log( shape2string( out )+'\n' ); -} diff --git a/include/stdlib/ndarray/base/broadcast_shapes.h b/include/stdlib/ndarray/base/broadcast_shapes.h deleted file mode 100644 index e23dce1..0000000 --- a/include/stdlib/ndarray/base/broadcast_shapes.h +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#ifndef STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H -#define STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H - -#include - -/* -* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. -*/ -#ifdef __cplusplus -extern "C" { -#endif - -/** -* Broadcasts array shapes to a single shape. -*/ -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H diff --git a/index.js b/index.js new file mode 100644 index 0000000..d225eb4 --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map new file mode 100644 index 0000000..0c02c0f --- /dev/null +++ b/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 0c9817e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Broadcast array shapes to a single shape. -* -* @module @stdlib/ndarray-base-broadcast-shapes -* -* @example -* var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); -* -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -*/ - -// 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 8558e60..0000000 --- a/lib/main.js +++ /dev/null @@ -1,256 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param {Array} shapes - array of shape arrays -* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`) -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [ 8, 0, 1, 6, 1 ], -* [ 8, 8, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -function broadcastShapes( shapes ) { - var ndims; - var out; - var dim; - var sh; - var n1; - var n2; - var d; - var M; - var N; - var i; - var j; - - M = shapes.length; - out = []; - if ( M === 0 ) { - return out; - } - sh = shapes[ 0 ]; - N = sh.length; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M === 1 ) { - // Need to manually copy to output shape, as shapes could be array-like objects... - for ( i = 0; i < N; i++ ) { - out.push( sh[ i ] ); - } - return out; - } - // Determine the maximum dimensionality... - ndims = [ N ]; - for ( i = 1; i < M; i++ ) { - ndims.push( shapes[ i ].length ); - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Initialize the output array... - for ( i = 0; i < N; i++ ) { - out.push( 0 ); - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim === 1 ) { - dim = d; - continue; - } - if ( d === 1 || dim === d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return null; - } - out[ i ] = dim; - i -= 1; - } - return out; -} - - -// EXPORTS // - -module.exports = broadcastShapes; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 890a937..0000000 --- a/manifest.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "options": {}, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [] - } - ] -} diff --git a/package.json b/package.json index 8e3322c..a9ff889 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,7 @@ "version": "0.2.2", "description": "Broadcast array shapes to a single shape.", "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", - "include": "./include", - "lib": "./lib", - "src": "./src", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "main": "./index.js", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,33 +12,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/types": "^0.3.2", - "@stdlib/utils-library-manifest": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/string-left-pad": "^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", "stdtypes", @@ -80,9 +27,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 35a3654..0000000 --- a/src/main.c +++ /dev/null @@ -1,118 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). -* -* - Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. -* -* @param M number of array shapes -* @param shapes pointer to an array containing shape arrays -* @param ndims array containing the number of dimensions for (i.e., length of) each respective shape array -* @param out pointer to output array -* @return status -* -* @example -* #include "stdlib/ndarray/base/broadcast_shapes.h" -* #include -* -* int64_t N1 = 4; -* int64_t sh1[] = { 8, 1, 6, 1 }; -* -* int64_t N2 = 3; -* int64_t sh2[] = { 7, 1, 5 }; -* -* int64_t ndims[] = { N1, N2 }; -* int64_t *shapes[] = { sh1, sh2 }; -* -* int64_t out[] = { 0, 0, 0, 0 }; -* int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -*/ -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ) { - int64_t dim; - int64_t *sh; - int64_t n1; - int64_t n2; - int64_t d; - int64_t N; - int64_t i; - int64_t j; - - if ( M == 0 ) { - return 0; - } - sh = shapes[ 0 ]; - N = ndims[ 0 ]; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M == 1 ) { - for ( i = 0; i < N; i++ ) { - out[ i ] = sh[ i ]; - } - return 0; - } - // Determine the maximum dimensionality... - for ( i = 1; i < M; i++ ) { - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim == 1 ) { - dim = d; - continue; - } - if ( d == 1 || dim == d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return -1; - } - out[ i ] = dim; - i -= 1; - } - return 0; -} diff --git a/stats_browser.html b/stats_browser.html new file mode 100644 index 0000000..2f35700 --- /dev/null +++ b/stats_browser.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/stats_node.html b/stats_node.html new file mode 100644 index 0000000..c264c7d --- /dev/null +++ b/stats_node.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 63f703c..0000000 --- a/test/test.js +++ /dev/null @@ -1,230 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var broadcastShapes = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastShapes, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] - ]; - - expected = [ - [ 1, 2 ], - [ 3, 4 ], - [ 5, 6, 7 ], - [ 3, 3 ], - [ 3 ], - [ 3, 2 ], - [ 2, 3 ], - [ 1, 2 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty dims)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 0 ], [ 0, 0 ] ], - [ [ 0, 1 ], [ 0, 0 ] ], - [ [ 1, 0 ], [ 0, 1 ] ], - [ [ 1, 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 1, 0 ] ], - [ [ 1, 1 ], [ 0, 1 ] ], - [ [ 0 ], [ 0, 0 ] ], - [ [ 0 ], [ 0, 1 ] ], - [ [ 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 0 ] ], - [ [ 1 ], [ 0, 1 ] ], - [ [ 1 ], [ 1, 0 ] ], - [ [ 1 ], [ 8, 0 ] ], - [ [ 8, 1, 6, 1 ], [ 0, 1, 5 ] ], - [ [ 8, 0, 6, 1 ], [ 1, 5 ] ] - ]; - - expected = [ - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 1, 0 ], - [ 8, 0 ], - [ 8, 0, 6, 5 ], - [ 8, 0, 6, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (no shapes)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [] - ]; - - expected = [ - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty shapes (i.e., zero-dimensional array broadcasting))', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [] ], - [ [], [] ], - [ [], [], [] ], - [ [], [ 0 ] ], - [ [ 0 ], [] ], - [ [], [ 0, 0 ] ], - [ [ 0, 0 ], [] ], - [ [], [ 1, 0 ] ], - [ [], [ 0, 1 ] ], - [ [], [ 3, 3 ] ], - [ [], [ 3, 3 ], [] ] - ]; - - expected = [ - [], - [], - [], - [ 0 ], - [ 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 3, 3 ], - [ 3, 3 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (single shape)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 7 ] ], - [ [ 1, 1 ] ], - [ [ 5, 6, 1 ] ] - ]; - - expected = [ - [ 7 ], - [ 1, 1 ], - [ 5, 6, 1 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function returns `null` if provided incompatible shapes', function test( t ) { - var actual; - var values; - var i; - - values = [ - [ [ 3 ], [ 4 ] ], - [ [ 2, 3 ], [ 2 ] ], - [ [ 3 ], [ 3 ], [ 4 ] ], - [ [ 1, 3, 4 ], [ 2, 3, 3 ] ], - [ [ 1, 2 ], [ 3, 1 ], [ 3, 2 ], [ 10, 5 ] ], - [ [ 2 ], [ 2, 3 ] ], - [ [ 2 ], [ 2 ], [ 2 ], [ 2 ], [ 3 ], [ 3 ], [ 3 ], [ 3 ] ], - [ [ 9, 0, 9 ], [ 0, 9, 0 ] ], - [ [ 9, 9, 9 ], [ 0, 9, 9 ] ], - [ [ 9, 0, 9 ], [ 9, 9, 9 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 0 ] ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.strictEqual( actual, null, 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); From ed1e4fbd25a9cacd9307c73efd8a8a90e17c0caa Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Sep 2024 02:03:48 +0000 Subject: [PATCH 120/158] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 4585eee..ea20c7c 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,8 @@ }, "dependencies": { "@stdlib/types": "^0.4.1", - "@stdlib/utils-library-manifest": "^0.2.2" + "@stdlib/utils-library-manifest": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, "devDependencies": { "@stdlib/string-left-pad": "^0.2.2", @@ -84,4 +85,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From 478a5343c8d1cd198cba692bb7faa461be01c681 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Sep 2024 03:45:54 +0000 Subject: [PATCH 121/158] Remove files --- browser.js | 3 - browser.js.map | 1 - index.js | 3 - index.js.map | 1 - stats_browser.html | 4842 -------------------------------------------- stats_node.html | 4842 -------------------------------------------- 6 files changed, 9692 deletions(-) delete mode 100644 browser.js delete mode 100644 browser.js.map delete mode 100644 index.js delete mode 100644 index.js.map delete mode 100644 stats_browser.html delete mode 100644 stats_node.html diff --git a/browser.js b/browser.js deleted file mode 100644 index 44a8074..0000000 --- a/browser.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); -//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map deleted file mode 100644 index aa4b2bb..0000000 --- a/browser.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"browser.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/index.js b/index.js deleted file mode 100644 index d225eb4..0000000 --- a/index.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); -//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map deleted file mode 100644 index 0c02c0f..0000000 --- a/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/stats_browser.html b/stats_browser.html deleted file mode 100644 index 2f35700..0000000 --- a/stats_browser.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - diff --git a/stats_node.html b/stats_node.html deleted file mode 100644 index c264c7d..0000000 --- a/stats_node.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 6e070fb66a958fb4b8f19635476b487672ef8931 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Sep 2024 03:46:07 +0000 Subject: [PATCH 122/158] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 240 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 178 +- SECURITY.md | 5 - benchmark/benchmark.js | 112 - benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 149 - branches.md | 56 - browser.js | 3 + browser.js.map | 1 + dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 39 - docs/types/index.d.ts | 177 - docs/types/test.ts | 45 - examples/c/Makefile | 146 - examples/c/example.c | 50 - examples/index.js | 54 - .../stdlib/ndarray/base/broadcast_shapes.h | 40 - index.js | 3 + index.js.map | 1 + lib/index.js | 45 - lib/main.js | 256 - manifest.json | 38 - package.json | 58 +- src/main.c | 118 - stats_browser.html | 4842 +++++++++++++++++ stats_node.html | 4842 +++++++++++++++++ test/dist/test.js | 33 - test/test.js | 230 - 53 files changed, 9729 insertions(+), 5369 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.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 branches.md create mode 100644 browser.js create mode 100644 browser.js.map 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/index.d.ts delete mode 100644 docs/types/test.ts delete mode 100644 examples/c/Makefile delete mode 100644 examples/c/example.c delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/broadcast_shapes.h create mode 100644 index.js create mode 100644 index.js.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 manifest.json delete mode 100644 src/main.c create mode 100644 stats_browser.html create mode 100644 stats_node.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/.keepalive b/.github/.keepalive deleted file mode 100644 index 6dc34a5..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-09-01T01:36:47.593Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 7f004ad..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 a07d970..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 7292af0..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: '0 12 * * 5' - - # 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 +``` -```javascript -var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); +If no recognized module system is present, access bundle contents via the global scope: + +```html + ``` #### broadcastShapes( shapes ) @@ -245,9 +251,14 @@ var sh = broadcastShapes( [ sh1, sh2 ] ); -```javascript -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); +```html + + + + + + + + ```
@@ -288,131 +304,7 @@ for ( i = 0; i < shapes.length; i++ ) { -* * * - -
- -## C APIs - - - -
- -
- - - - - -
- -### Usage - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -``` - -#### stdlib_ndarray_broadcast_shapes( M, \*\*shapes, \*ndims, \*out ) - -Broadcasts array shapes to a single shape. - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -int64_t N1 = 4; -int64_t sh1[] = { 8, 1, 6, 1 }; - -int64_t N2 = 3; -int64_t sh2[] = { 7, 1, 5 }; - -int64_t ndims[] = { N1, N2 }; -int64_t *shapes[] = { sh1, sh2 }; - -int64_t out[] = { 0, 0, 0, 0 }; -int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -if ( status != 0 ) { - // Handle error... -} -``` - -The function accepts the following arguments: - -- **M**: `[in] int64_t` number of shape arrays. -- **shapes**: `[in] int64_t**` array of shape arrays (dimensions). -- **ndims**: `[in] int64_t*` number of dimensions for each respective shape array. -- **out**: `[out] int64_t*` output shape array. - -```c -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ); -``` - -If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). - -
- - - - - -
- -### Notes - -- Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. - -
- - - - - -
- -### Examples - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main( void ) { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} -``` - -
- - - -
- 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.js b/benchmark/benchmark.js deleted file mode 100644 index 6426216..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,112 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pkg = require( './../package.json' ).name; -var broadcastShapes = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::two_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ] ], - [ [ 3, 2 ], [ 3, 1 ] ], - [ [ 1, 1 ], [ 2, 2 ] ], - [ [ 1 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::three_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::four_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ], [ 8, 1, 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ], [ 1, 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ], [ 1, 1, 2, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ], [ 1 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ], [ 5, 1, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/c/Makefile b/benchmark/c/Makefile deleted file mode 100644 index 5dc545c..0000000 --- a/benchmark/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := benchmark.out - - -# RULES # - -#/ -# Compiles C source files. -# -# @param {string} SOURCE_FILES - list of C source files -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lpthread -lblas`) -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [C_COMPILER] - C compiler -# @param {string} [CFLAGS] - C compiler flags -# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} SOURCE_FILES - list of C source files -# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {(string|void)} LIBRARIES - list of libraries (e.g., `-lpthread -lblas`) -# @param {(string|void)} LIBPATH - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} CC - C compiler -# @param {string} CFLAGS - C compiler flags -# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled benchmarks. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/benchmark/c/benchmark.c b/benchmark/c/benchmark.c deleted file mode 100644 index 82d2be5..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,149 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "broadcast-shapes" -#define ITERATIONS 1000000 -#define REPEATS 3 - -/** -* Prints the TAP version. -*/ -static void print_version( void ) { - printf( "TAP version 13\n" ); -} - -/** -* Prints the TAP summary. -* -* @param total total number of tests -* @param passing total number of passing tests -*/ -static void print_summary( int total, int passing ) { - printf( "#\n" ); - printf( "1..%d\n", total ); // TAP plan - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); -} - -/** -* Prints benchmarks results. -* -* @param elapsed elapsed time in seconds -*/ -static void print_results( double elapsed ) { - double rate = (double)ITERATIONS / elapsed; - printf( " ---\n" ); - printf( " iterations: %d\n", ITERATIONS ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", rate ); - printf( " ...\n" ); -} - -/** -* Returns a clock time. -* -* @return clock time -*/ -static double tic( void ) { - struct timeval now; - gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; -} - -/** -* Generates a random number on the interval [0,1). -* -* @return random number -*/ -static double rand_double( void ) { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark( void ) { - double elapsed; - int8_t status; - double t; - int i; - - const int64_t sh1[] = { 8, 1, 6, 1 }; - const int64_t sh2[] = { 7, 1, 5 }; - - const int64_t ndims[] = { 4, 3 }; - const int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( out[ 0 ] != 8 ) { - printf( "unexpected result\n" ); - } - if ( out[ 1 ] != 7 ) { - printf( "unexpected result\n" ); - } - if ( out[ 2 ] != 6 ) { - printf( "unexpected result\n" ); - } - if ( out[ 3 ] != 5 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Main execution sequence. -*/ -int main( void ) { - double elapsed; - int i; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - for ( i = 0; i < REPEATS; i++ ) { - printf( "# c::native::%s::two_arrays\n", NAME ); - elapsed = benchmark(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", i+1 ); - } - print_summary( REPEATS, REPEATS ); -} diff --git a/branches.md b/branches.md deleted file mode 100644 index 79909c9..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes" -%% click B href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/blob/esm/README.md \ No newline at end of file diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..44a8074 --- /dev/null +++ b/browser.js @@ -0,0 +1,3 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map new file mode 100644 index 0000000..aa4b2bb --- /dev/null +++ b/browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"browser.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 87ea8b6..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import broadcastShapes from '../docs/types/index'; -export = broadcastShapes; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 625741a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var d=function(t,e){return function(){return e||t((e={exports:{}}).exports,e),e.exports}};var h=d(function(x,c){ -function g(t){var e,n,u,o,s,l,a,f,i,r,v;if(f=t.length,n=[],f===0)return n;if(o=t[0],i=o.length,f===1){for(r=0;ri&&(i=e[r]);for(r=0;r=0;){for(s=e[0]-i+r,s>=0?u=o[s]:u=1,v=1;v=0?a=t[v][l]:a=1,u===1){u=a;continue}if(!(a===1||u===a))return null}n[r]=u,r-=1}return n}c.exports=g -});var m=h();module.exports=m; -/** @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 db2949f..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = broadcastShapes;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast array shapes to a single shape.\n*\n* @module @stdlib/ndarray-base-broadcast-shapes\n*\n* @example\n* var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' );\n*\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\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,cAkLA,SAASC,EAAiBC,EAAS,CAClC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GAFAH,EAAIR,EAAO,OACXE,EAAM,CAAC,EACFM,IAAM,EACV,OAAON,EAMR,GAJAE,EAAKJ,EAAQ,CAAE,EACfS,EAAIL,EAAG,OAGFI,IAAM,EAAI,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAI,KAAME,EAAIM,CAAE,CAAE,EAEnB,OAAOR,CACR,CAGA,IADAD,EAAQ,CAAEQ,CAAE,EACNC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAM,KAAMD,EAAQU,CAAE,EAAE,MAAO,EAC1BT,EAAOS,CAAE,EAAID,IACjBA,EAAIR,EAAOS,CAAE,GAIf,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAI,KAAM,CAAE,EAIb,IADAQ,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IANAL,EAAKJ,EAAO,CAAE,EAAIQ,EAAIC,EACjBL,GAAM,EACVF,EAAMC,EAAIC,CAAG,EAEbF,EAAM,EAEDQ,EAAI,EAAGA,EAAIH,EAAGG,IAAM,CAOzB,GANAL,EAAKL,EAAOU,CAAE,EAAIF,EAAIC,EACjBJ,GAAM,EACVC,EAAIP,EAAQW,CAAE,EAAGL,CAAG,EAEpBC,EAAI,EAEAJ,IAAQ,EAAI,CAChBA,EAAMI,EACN,QACD,CACA,GAAK,EAAAA,IAAM,GAAKJ,IAAQI,GAKxB,OAAO,IACR,CACAL,EAAKQ,CAAE,EAAIP,EACXO,GAAK,CACN,CACA,OAAOR,CACR,CAKAJ,EAAO,QAAUC,ICxNjB,IAAIa,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "broadcastShapes", "shapes", "ndims", "out", "dim", "sh", "n1", "n2", "d", "M", "N", "i", "j", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f1d92f6..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,39 +0,0 @@ - -{{alias}}( shapes ) - Broadcasts array shapes to a single shape. - - Two respective dimensions in two shape arrays are compatible if - - 1. the dimensions are equal. - 2. one dimension is `1`. - - The function returns `null` if provided incompatible shapes (i.e., shapes - which cannot be broadcast with one another). - - Parameters - ---------- - shapes: Array - Array of shape arrays. - - Returns - ------- - out: Array|null - Broadcast shape. - - Examples - -------- - // Compatible shapes: - > var sh1 = [ 8, 1, 6, 1 ]; - > var sh2 = [ 7, 1, 5 ]; - > var sh = {{alias}}( [ sh1, sh2 ] ) - [ 8, 7, 6, 5 ] - - // Incompatible shapes: - > sh1 = [ 3, 2 ]; - > sh1 = [ 2, 3 ]; - > sh = {{alias}}( [ sh1, sh2 ] ) - null - - See Also - -------- - diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts deleted file mode 100644 index c2702cf..0000000 --- a/docs/types/index.d.ts +++ /dev/null @@ -1,177 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ArrayLike } from '@stdlib/types/array'; - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param shapes - array shapes -* @returns broadcast shape -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -declare function broadcastShapes( shapes: ArrayLike> ): ArrayLike; - - -// EXPORTS // - -export = broadcastShapes; diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 2886539..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 broadcastShapes = require( './index' ); - - -// TESTS // - -// The function returns an array of numbers... -{ - broadcastShapes( [ [ 1, 2 ], [ 2, 2 ] ] ); // $ExpectType ArrayLike -} - -// The compiler throws an error if the function is not provided an array-like object containing array-like objects containing numbers... -{ - broadcastShapes( '5' ); // $ExpectError - broadcastShapes( 5 ); // $ExpectError - broadcastShapes( true ); // $ExpectError - broadcastShapes( false ); // $ExpectError - broadcastShapes( null ); // $ExpectError - broadcastShapes( {} ); // $ExpectError - broadcastShapes( [ '5' ] ); // $ExpectError - broadcastShapes( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - broadcastShapes(); // $ExpectError - broadcastShapes( [ [ 1, 2, 3 ] ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/c/Makefile b/examples/c/Makefile deleted file mode 100644 index 70c91f4..0000000 --- a/examples/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := example.out - - -# RULES # - -#/ -# Compiles source files. -# -# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) -# @param {string} [CFLAGS] - C compiler options -# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) -# @param {string} [SOURCE_FILES] - list of source files -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} CC - C compiler (e.g., `gcc`) -# @param {string} CFLAGS - C compiler options -# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) -# @param {string} SOURCE_FILES - list of source files -# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) -# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled examples. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/examples/c/example.c b/examples/c/example.c deleted file mode 100644 index 4bc54d5..0000000 --- a/examples/c/example.c +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main( void ) { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 28811f9..0000000 --- a/examples/index.js +++ /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. -*/ - -'use strict'; - -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( './../lib' ); - -var shapes; -var out; -var sh; -var i; -var j; - -function shape2string( shape ) { - return lpad( shape.join( ' x ' ), 20, ' ' ); -} - -shapes = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] -]; - -for ( i = 0; i < shapes.length; i++ ) { - sh = shapes[ i ]; - for ( j = 0; j < sh.length; j++ ) { - console.log( shape2string( sh[ j ] ) ); - } - console.log( lpad( '', 20, '-' ) ); - - out = broadcastShapes( sh ); - console.log( shape2string( out )+'\n' ); -} diff --git a/include/stdlib/ndarray/base/broadcast_shapes.h b/include/stdlib/ndarray/base/broadcast_shapes.h deleted file mode 100644 index e23dce1..0000000 --- a/include/stdlib/ndarray/base/broadcast_shapes.h +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#ifndef STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H -#define STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H - -#include - -/* -* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. -*/ -#ifdef __cplusplus -extern "C" { -#endif - -/** -* Broadcasts array shapes to a single shape. -*/ -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H diff --git a/index.js b/index.js new file mode 100644 index 0000000..d225eb4 --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map new file mode 100644 index 0000000..0c02c0f --- /dev/null +++ b/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 0c9817e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Broadcast array shapes to a single shape. -* -* @module @stdlib/ndarray-base-broadcast-shapes -* -* @example -* var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); -* -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -*/ - -// 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 8558e60..0000000 --- a/lib/main.js +++ /dev/null @@ -1,256 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param {Array} shapes - array of shape arrays -* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`) -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [ 8, 0, 1, 6, 1 ], -* [ 8, 8, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -function broadcastShapes( shapes ) { - var ndims; - var out; - var dim; - var sh; - var n1; - var n2; - var d; - var M; - var N; - var i; - var j; - - M = shapes.length; - out = []; - if ( M === 0 ) { - return out; - } - sh = shapes[ 0 ]; - N = sh.length; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M === 1 ) { - // Need to manually copy to output shape, as shapes could be array-like objects... - for ( i = 0; i < N; i++ ) { - out.push( sh[ i ] ); - } - return out; - } - // Determine the maximum dimensionality... - ndims = [ N ]; - for ( i = 1; i < M; i++ ) { - ndims.push( shapes[ i ].length ); - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Initialize the output array... - for ( i = 0; i < N; i++ ) { - out.push( 0 ); - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim === 1 ) { - dim = d; - continue; - } - if ( d === 1 || dim === d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return null; - } - out[ i ] = dim; - i -= 1; - } - return out; -} - - -// EXPORTS // - -module.exports = broadcastShapes; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 890a937..0000000 --- a/manifest.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "options": {}, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [] - } - ] -} diff --git a/package.json b/package.json index ea20c7c..a9ff889 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,7 @@ "version": "0.2.2", "description": "Broadcast array shapes to a single shape.", "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", - "include": "./include", - "lib": "./lib", - "src": "./src", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "main": "./index.js", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,33 +12,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/types": "^0.4.1", - "@stdlib/utils-library-manifest": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/string-left-pad": "^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", "stdtypes", @@ -80,9 +27,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 35a3654..0000000 --- a/src/main.c +++ /dev/null @@ -1,118 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). -* -* - Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. -* -* @param M number of array shapes -* @param shapes pointer to an array containing shape arrays -* @param ndims array containing the number of dimensions for (i.e., length of) each respective shape array -* @param out pointer to output array -* @return status -* -* @example -* #include "stdlib/ndarray/base/broadcast_shapes.h" -* #include -* -* int64_t N1 = 4; -* int64_t sh1[] = { 8, 1, 6, 1 }; -* -* int64_t N2 = 3; -* int64_t sh2[] = { 7, 1, 5 }; -* -* int64_t ndims[] = { N1, N2 }; -* int64_t *shapes[] = { sh1, sh2 }; -* -* int64_t out[] = { 0, 0, 0, 0 }; -* int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -*/ -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ) { - int64_t dim; - int64_t *sh; - int64_t n1; - int64_t n2; - int64_t d; - int64_t N; - int64_t i; - int64_t j; - - if ( M == 0 ) { - return 0; - } - sh = shapes[ 0 ]; - N = ndims[ 0 ]; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M == 1 ) { - for ( i = 0; i < N; i++ ) { - out[ i ] = sh[ i ]; - } - return 0; - } - // Determine the maximum dimensionality... - for ( i = 1; i < M; i++ ) { - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim == 1 ) { - dim = d; - continue; - } - if ( d == 1 || dim == d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return -1; - } - out[ i ] = dim; - i -= 1; - } - return 0; -} diff --git a/stats_browser.html b/stats_browser.html new file mode 100644 index 0000000..2f35700 --- /dev/null +++ b/stats_browser.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/stats_node.html b/stats_node.html new file mode 100644 index 0000000..c264c7d --- /dev/null +++ b/stats_node.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 63f703c..0000000 --- a/test/test.js +++ /dev/null @@ -1,230 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var broadcastShapes = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastShapes, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] - ]; - - expected = [ - [ 1, 2 ], - [ 3, 4 ], - [ 5, 6, 7 ], - [ 3, 3 ], - [ 3 ], - [ 3, 2 ], - [ 2, 3 ], - [ 1, 2 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty dims)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 0 ], [ 0, 0 ] ], - [ [ 0, 1 ], [ 0, 0 ] ], - [ [ 1, 0 ], [ 0, 1 ] ], - [ [ 1, 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 1, 0 ] ], - [ [ 1, 1 ], [ 0, 1 ] ], - [ [ 0 ], [ 0, 0 ] ], - [ [ 0 ], [ 0, 1 ] ], - [ [ 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 0 ] ], - [ [ 1 ], [ 0, 1 ] ], - [ [ 1 ], [ 1, 0 ] ], - [ [ 1 ], [ 8, 0 ] ], - [ [ 8, 1, 6, 1 ], [ 0, 1, 5 ] ], - [ [ 8, 0, 6, 1 ], [ 1, 5 ] ] - ]; - - expected = [ - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 1, 0 ], - [ 8, 0 ], - [ 8, 0, 6, 5 ], - [ 8, 0, 6, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (no shapes)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [] - ]; - - expected = [ - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty shapes (i.e., zero-dimensional array broadcasting))', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [] ], - [ [], [] ], - [ [], [], [] ], - [ [], [ 0 ] ], - [ [ 0 ], [] ], - [ [], [ 0, 0 ] ], - [ [ 0, 0 ], [] ], - [ [], [ 1, 0 ] ], - [ [], [ 0, 1 ] ], - [ [], [ 3, 3 ] ], - [ [], [ 3, 3 ], [] ] - ]; - - expected = [ - [], - [], - [], - [ 0 ], - [ 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 3, 3 ], - [ 3, 3 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (single shape)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 7 ] ], - [ [ 1, 1 ] ], - [ [ 5, 6, 1 ] ] - ]; - - expected = [ - [ 7 ], - [ 1, 1 ], - [ 5, 6, 1 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function returns `null` if provided incompatible shapes', function test( t ) { - var actual; - var values; - var i; - - values = [ - [ [ 3 ], [ 4 ] ], - [ [ 2, 3 ], [ 2 ] ], - [ [ 3 ], [ 3 ], [ 4 ] ], - [ [ 1, 3, 4 ], [ 2, 3, 3 ] ], - [ [ 1, 2 ], [ 3, 1 ], [ 3, 2 ], [ 10, 5 ] ], - [ [ 2 ], [ 2, 3 ] ], - [ [ 2 ], [ 2 ], [ 2 ], [ 2 ], [ 3 ], [ 3 ], [ 3 ], [ 3 ] ], - [ [ 9, 0, 9 ], [ 0, 9, 0 ] ], - [ [ 9, 9, 9 ], [ 0, 9, 9 ] ], - [ [ 9, 0, 9 ], [ 9, 9, 9 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 0 ] ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.strictEqual( actual, null, 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); From 3422250eec720febd85dbeee3677871c7c01b547 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Oct 2024 02:09:06 +0000 Subject: [PATCH 123/158] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 4585eee..ea20c7c 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,8 @@ }, "dependencies": { "@stdlib/types": "^0.4.1", - "@stdlib/utils-library-manifest": "^0.2.2" + "@stdlib/utils-library-manifest": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, "devDependencies": { "@stdlib/string-left-pad": "^0.2.2", @@ -84,4 +85,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From 0ad63ef603b776e4c666f7905a76917f8bf710a7 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Oct 2024 03:45:52 +0000 Subject: [PATCH 124/158] Remove files --- browser.js | 3 - browser.js.map | 1 - index.js | 3 - index.js.map | 1 - stats_browser.html | 4842 -------------------------------------------- stats_node.html | 4842 -------------------------------------------- 6 files changed, 9692 deletions(-) delete mode 100644 browser.js delete mode 100644 browser.js.map delete mode 100644 index.js delete mode 100644 index.js.map delete mode 100644 stats_browser.html delete mode 100644 stats_node.html diff --git a/browser.js b/browser.js deleted file mode 100644 index 44a8074..0000000 --- a/browser.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); -//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map deleted file mode 100644 index aa4b2bb..0000000 --- a/browser.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"browser.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/index.js b/index.js deleted file mode 100644 index d225eb4..0000000 --- a/index.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); -//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map deleted file mode 100644 index 0c02c0f..0000000 --- a/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/stats_browser.html b/stats_browser.html deleted file mode 100644 index 2f35700..0000000 --- a/stats_browser.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - diff --git a/stats_node.html b/stats_node.html deleted file mode 100644 index c264c7d..0000000 --- a/stats_node.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 4bdba651443deb5e108f2851b3207960ba64f049 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Oct 2024 03:46:09 +0000 Subject: [PATCH 125/158] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 240 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 178 +- SECURITY.md | 5 - benchmark/benchmark.js | 112 - benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 149 - branches.md | 56 - browser.js | 3 + browser.js.map | 1 + dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 39 - docs/types/index.d.ts | 177 - docs/types/test.ts | 45 - examples/c/Makefile | 146 - examples/c/example.c | 50 - examples/index.js | 54 - .../stdlib/ndarray/base/broadcast_shapes.h | 40 - index.js | 3 + index.js.map | 1 + lib/index.js | 45 - lib/main.js | 256 - manifest.json | 38 - package.json | 58 +- src/main.c | 118 - stats_browser.html | 4842 +++++++++++++++++ stats_node.html | 4842 +++++++++++++++++ test/dist/test.js | 33 - test/test.js | 230 - 53 files changed, 9729 insertions(+), 5369 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.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 branches.md create mode 100644 browser.js create mode 100644 browser.js.map 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/index.d.ts delete mode 100644 docs/types/test.ts delete mode 100644 examples/c/Makefile delete mode 100644 examples/c/example.c delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/broadcast_shapes.h create mode 100644 index.js create mode 100644 index.js.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 manifest.json delete mode 100644 src/main.c create mode 100644 stats_browser.html create mode 100644 stats_node.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/.keepalive b/.github/.keepalive deleted file mode 100644 index b77b1f0..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-10-01T01:43:14.574Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 7f004ad..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 a07d970..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 7292af0..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: '0 12 * * 5' - - # 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 +``` -```javascript -var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); +If no recognized module system is present, access bundle contents via the global scope: + +```html + ``` #### broadcastShapes( shapes ) @@ -245,9 +251,14 @@ var sh = broadcastShapes( [ sh1, sh2 ] ); -```javascript -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); +```html + + + + + + + + ```
@@ -288,131 +304,7 @@ for ( i = 0; i < shapes.length; i++ ) { -* * * - -
- -## C APIs - - - -
- -
- - - - - -
- -### Usage - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -``` - -#### stdlib_ndarray_broadcast_shapes( M, \*\*shapes, \*ndims, \*out ) - -Broadcasts array shapes to a single shape. - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -int64_t N1 = 4; -int64_t sh1[] = { 8, 1, 6, 1 }; - -int64_t N2 = 3; -int64_t sh2[] = { 7, 1, 5 }; - -int64_t ndims[] = { N1, N2 }; -int64_t *shapes[] = { sh1, sh2 }; - -int64_t out[] = { 0, 0, 0, 0 }; -int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -if ( status != 0 ) { - // Handle error... -} -``` - -The function accepts the following arguments: - -- **M**: `[in] int64_t` number of shape arrays. -- **shapes**: `[in] int64_t**` array of shape arrays (dimensions). -- **ndims**: `[in] int64_t*` number of dimensions for each respective shape array. -- **out**: `[out] int64_t*` output shape array. - -```c -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ); -``` - -If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). - -
- - - - - -
- -### Notes - -- Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. - -
- - - - - -
- -### Examples - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main( void ) { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} -``` - -
- - - -
- 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.js b/benchmark/benchmark.js deleted file mode 100644 index 6426216..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,112 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pkg = require( './../package.json' ).name; -var broadcastShapes = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::two_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ] ], - [ [ 3, 2 ], [ 3, 1 ] ], - [ [ 1, 1 ], [ 2, 2 ] ], - [ [ 1 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::three_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::four_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ], [ 8, 1, 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ], [ 1, 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ], [ 1, 1, 2, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ], [ 1 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ], [ 5, 1, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/c/Makefile b/benchmark/c/Makefile deleted file mode 100644 index 5dc545c..0000000 --- a/benchmark/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := benchmark.out - - -# RULES # - -#/ -# Compiles C source files. -# -# @param {string} SOURCE_FILES - list of C source files -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lpthread -lblas`) -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [C_COMPILER] - C compiler -# @param {string} [CFLAGS] - C compiler flags -# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} SOURCE_FILES - list of C source files -# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {(string|void)} LIBRARIES - list of libraries (e.g., `-lpthread -lblas`) -# @param {(string|void)} LIBPATH - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} CC - C compiler -# @param {string} CFLAGS - C compiler flags -# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled benchmarks. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/benchmark/c/benchmark.c b/benchmark/c/benchmark.c deleted file mode 100644 index 82d2be5..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,149 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "broadcast-shapes" -#define ITERATIONS 1000000 -#define REPEATS 3 - -/** -* Prints the TAP version. -*/ -static void print_version( void ) { - printf( "TAP version 13\n" ); -} - -/** -* Prints the TAP summary. -* -* @param total total number of tests -* @param passing total number of passing tests -*/ -static void print_summary( int total, int passing ) { - printf( "#\n" ); - printf( "1..%d\n", total ); // TAP plan - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); -} - -/** -* Prints benchmarks results. -* -* @param elapsed elapsed time in seconds -*/ -static void print_results( double elapsed ) { - double rate = (double)ITERATIONS / elapsed; - printf( " ---\n" ); - printf( " iterations: %d\n", ITERATIONS ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", rate ); - printf( " ...\n" ); -} - -/** -* Returns a clock time. -* -* @return clock time -*/ -static double tic( void ) { - struct timeval now; - gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; -} - -/** -* Generates a random number on the interval [0,1). -* -* @return random number -*/ -static double rand_double( void ) { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark( void ) { - double elapsed; - int8_t status; - double t; - int i; - - const int64_t sh1[] = { 8, 1, 6, 1 }; - const int64_t sh2[] = { 7, 1, 5 }; - - const int64_t ndims[] = { 4, 3 }; - const int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( out[ 0 ] != 8 ) { - printf( "unexpected result\n" ); - } - if ( out[ 1 ] != 7 ) { - printf( "unexpected result\n" ); - } - if ( out[ 2 ] != 6 ) { - printf( "unexpected result\n" ); - } - if ( out[ 3 ] != 5 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Main execution sequence. -*/ -int main( void ) { - double elapsed; - int i; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - for ( i = 0; i < REPEATS; i++ ) { - printf( "# c::native::%s::two_arrays\n", NAME ); - elapsed = benchmark(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", i+1 ); - } - print_summary( REPEATS, REPEATS ); -} diff --git a/branches.md b/branches.md deleted file mode 100644 index 79909c9..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes" -%% click B href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/blob/esm/README.md \ No newline at end of file diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..44a8074 --- /dev/null +++ b/browser.js @@ -0,0 +1,3 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map new file mode 100644 index 0000000..aa4b2bb --- /dev/null +++ b/browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"browser.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 87ea8b6..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import broadcastShapes from '../docs/types/index'; -export = broadcastShapes; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 625741a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var d=function(t,e){return function(){return e||t((e={exports:{}}).exports,e),e.exports}};var h=d(function(x,c){ -function g(t){var e,n,u,o,s,l,a,f,i,r,v;if(f=t.length,n=[],f===0)return n;if(o=t[0],i=o.length,f===1){for(r=0;ri&&(i=e[r]);for(r=0;r=0;){for(s=e[0]-i+r,s>=0?u=o[s]:u=1,v=1;v=0?a=t[v][l]:a=1,u===1){u=a;continue}if(!(a===1||u===a))return null}n[r]=u,r-=1}return n}c.exports=g -});var m=h();module.exports=m; -/** @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 db2949f..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = broadcastShapes;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast array shapes to a single shape.\n*\n* @module @stdlib/ndarray-base-broadcast-shapes\n*\n* @example\n* var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' );\n*\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\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,cAkLA,SAASC,EAAiBC,EAAS,CAClC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GAFAH,EAAIR,EAAO,OACXE,EAAM,CAAC,EACFM,IAAM,EACV,OAAON,EAMR,GAJAE,EAAKJ,EAAQ,CAAE,EACfS,EAAIL,EAAG,OAGFI,IAAM,EAAI,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAI,KAAME,EAAIM,CAAE,CAAE,EAEnB,OAAOR,CACR,CAGA,IADAD,EAAQ,CAAEQ,CAAE,EACNC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAM,KAAMD,EAAQU,CAAE,EAAE,MAAO,EAC1BT,EAAOS,CAAE,EAAID,IACjBA,EAAIR,EAAOS,CAAE,GAIf,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAI,KAAM,CAAE,EAIb,IADAQ,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IANAL,EAAKJ,EAAO,CAAE,EAAIQ,EAAIC,EACjBL,GAAM,EACVF,EAAMC,EAAIC,CAAG,EAEbF,EAAM,EAEDQ,EAAI,EAAGA,EAAIH,EAAGG,IAAM,CAOzB,GANAL,EAAKL,EAAOU,CAAE,EAAIF,EAAIC,EACjBJ,GAAM,EACVC,EAAIP,EAAQW,CAAE,EAAGL,CAAG,EAEpBC,EAAI,EAEAJ,IAAQ,EAAI,CAChBA,EAAMI,EACN,QACD,CACA,GAAK,EAAAA,IAAM,GAAKJ,IAAQI,GAKxB,OAAO,IACR,CACAL,EAAKQ,CAAE,EAAIP,EACXO,GAAK,CACN,CACA,OAAOR,CACR,CAKAJ,EAAO,QAAUC,ICxNjB,IAAIa,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "broadcastShapes", "shapes", "ndims", "out", "dim", "sh", "n1", "n2", "d", "M", "N", "i", "j", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f1d92f6..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,39 +0,0 @@ - -{{alias}}( shapes ) - Broadcasts array shapes to a single shape. - - Two respective dimensions in two shape arrays are compatible if - - 1. the dimensions are equal. - 2. one dimension is `1`. - - The function returns `null` if provided incompatible shapes (i.e., shapes - which cannot be broadcast with one another). - - Parameters - ---------- - shapes: Array - Array of shape arrays. - - Returns - ------- - out: Array|null - Broadcast shape. - - Examples - -------- - // Compatible shapes: - > var sh1 = [ 8, 1, 6, 1 ]; - > var sh2 = [ 7, 1, 5 ]; - > var sh = {{alias}}( [ sh1, sh2 ] ) - [ 8, 7, 6, 5 ] - - // Incompatible shapes: - > sh1 = [ 3, 2 ]; - > sh1 = [ 2, 3 ]; - > sh = {{alias}}( [ sh1, sh2 ] ) - null - - See Also - -------- - diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts deleted file mode 100644 index c2702cf..0000000 --- a/docs/types/index.d.ts +++ /dev/null @@ -1,177 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ArrayLike } from '@stdlib/types/array'; - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param shapes - array shapes -* @returns broadcast shape -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -declare function broadcastShapes( shapes: ArrayLike> ): ArrayLike; - - -// EXPORTS // - -export = broadcastShapes; diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 2886539..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 broadcastShapes = require( './index' ); - - -// TESTS // - -// The function returns an array of numbers... -{ - broadcastShapes( [ [ 1, 2 ], [ 2, 2 ] ] ); // $ExpectType ArrayLike -} - -// The compiler throws an error if the function is not provided an array-like object containing array-like objects containing numbers... -{ - broadcastShapes( '5' ); // $ExpectError - broadcastShapes( 5 ); // $ExpectError - broadcastShapes( true ); // $ExpectError - broadcastShapes( false ); // $ExpectError - broadcastShapes( null ); // $ExpectError - broadcastShapes( {} ); // $ExpectError - broadcastShapes( [ '5' ] ); // $ExpectError - broadcastShapes( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - broadcastShapes(); // $ExpectError - broadcastShapes( [ [ 1, 2, 3 ] ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/c/Makefile b/examples/c/Makefile deleted file mode 100644 index 70c91f4..0000000 --- a/examples/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := example.out - - -# RULES # - -#/ -# Compiles source files. -# -# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) -# @param {string} [CFLAGS] - C compiler options -# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) -# @param {string} [SOURCE_FILES] - list of source files -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} CC - C compiler (e.g., `gcc`) -# @param {string} CFLAGS - C compiler options -# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) -# @param {string} SOURCE_FILES - list of source files -# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) -# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled examples. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/examples/c/example.c b/examples/c/example.c deleted file mode 100644 index 4bc54d5..0000000 --- a/examples/c/example.c +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main( void ) { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 28811f9..0000000 --- a/examples/index.js +++ /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. -*/ - -'use strict'; - -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( './../lib' ); - -var shapes; -var out; -var sh; -var i; -var j; - -function shape2string( shape ) { - return lpad( shape.join( ' x ' ), 20, ' ' ); -} - -shapes = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] -]; - -for ( i = 0; i < shapes.length; i++ ) { - sh = shapes[ i ]; - for ( j = 0; j < sh.length; j++ ) { - console.log( shape2string( sh[ j ] ) ); - } - console.log( lpad( '', 20, '-' ) ); - - out = broadcastShapes( sh ); - console.log( shape2string( out )+'\n' ); -} diff --git a/include/stdlib/ndarray/base/broadcast_shapes.h b/include/stdlib/ndarray/base/broadcast_shapes.h deleted file mode 100644 index e23dce1..0000000 --- a/include/stdlib/ndarray/base/broadcast_shapes.h +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#ifndef STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H -#define STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H - -#include - -/* -* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. -*/ -#ifdef __cplusplus -extern "C" { -#endif - -/** -* Broadcasts array shapes to a single shape. -*/ -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H diff --git a/index.js b/index.js new file mode 100644 index 0000000..d225eb4 --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map new file mode 100644 index 0000000..0c02c0f --- /dev/null +++ b/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 0c9817e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Broadcast array shapes to a single shape. -* -* @module @stdlib/ndarray-base-broadcast-shapes -* -* @example -* var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); -* -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -*/ - -// 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 8558e60..0000000 --- a/lib/main.js +++ /dev/null @@ -1,256 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param {Array} shapes - array of shape arrays -* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`) -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [ 8, 0, 1, 6, 1 ], -* [ 8, 8, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -function broadcastShapes( shapes ) { - var ndims; - var out; - var dim; - var sh; - var n1; - var n2; - var d; - var M; - var N; - var i; - var j; - - M = shapes.length; - out = []; - if ( M === 0 ) { - return out; - } - sh = shapes[ 0 ]; - N = sh.length; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M === 1 ) { - // Need to manually copy to output shape, as shapes could be array-like objects... - for ( i = 0; i < N; i++ ) { - out.push( sh[ i ] ); - } - return out; - } - // Determine the maximum dimensionality... - ndims = [ N ]; - for ( i = 1; i < M; i++ ) { - ndims.push( shapes[ i ].length ); - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Initialize the output array... - for ( i = 0; i < N; i++ ) { - out.push( 0 ); - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim === 1 ) { - dim = d; - continue; - } - if ( d === 1 || dim === d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return null; - } - out[ i ] = dim; - i -= 1; - } - return out; -} - - -// EXPORTS // - -module.exports = broadcastShapes; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 890a937..0000000 --- a/manifest.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "options": {}, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [] - } - ] -} diff --git a/package.json b/package.json index ea20c7c..a9ff889 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,7 @@ "version": "0.2.2", "description": "Broadcast array shapes to a single shape.", "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", - "include": "./include", - "lib": "./lib", - "src": "./src", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "main": "./index.js", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,33 +12,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/types": "^0.4.1", - "@stdlib/utils-library-manifest": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/string-left-pad": "^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", "stdtypes", @@ -80,9 +27,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 35a3654..0000000 --- a/src/main.c +++ /dev/null @@ -1,118 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). -* -* - Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. -* -* @param M number of array shapes -* @param shapes pointer to an array containing shape arrays -* @param ndims array containing the number of dimensions for (i.e., length of) each respective shape array -* @param out pointer to output array -* @return status -* -* @example -* #include "stdlib/ndarray/base/broadcast_shapes.h" -* #include -* -* int64_t N1 = 4; -* int64_t sh1[] = { 8, 1, 6, 1 }; -* -* int64_t N2 = 3; -* int64_t sh2[] = { 7, 1, 5 }; -* -* int64_t ndims[] = { N1, N2 }; -* int64_t *shapes[] = { sh1, sh2 }; -* -* int64_t out[] = { 0, 0, 0, 0 }; -* int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -*/ -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ) { - int64_t dim; - int64_t *sh; - int64_t n1; - int64_t n2; - int64_t d; - int64_t N; - int64_t i; - int64_t j; - - if ( M == 0 ) { - return 0; - } - sh = shapes[ 0 ]; - N = ndims[ 0 ]; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M == 1 ) { - for ( i = 0; i < N; i++ ) { - out[ i ] = sh[ i ]; - } - return 0; - } - // Determine the maximum dimensionality... - for ( i = 1; i < M; i++ ) { - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim == 1 ) { - dim = d; - continue; - } - if ( d == 1 || dim == d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return -1; - } - out[ i ] = dim; - i -= 1; - } - return 0; -} diff --git a/stats_browser.html b/stats_browser.html new file mode 100644 index 0000000..2f35700 --- /dev/null +++ b/stats_browser.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/stats_node.html b/stats_node.html new file mode 100644 index 0000000..c264c7d --- /dev/null +++ b/stats_node.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 63f703c..0000000 --- a/test/test.js +++ /dev/null @@ -1,230 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var broadcastShapes = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastShapes, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] - ]; - - expected = [ - [ 1, 2 ], - [ 3, 4 ], - [ 5, 6, 7 ], - [ 3, 3 ], - [ 3 ], - [ 3, 2 ], - [ 2, 3 ], - [ 1, 2 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty dims)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 0 ], [ 0, 0 ] ], - [ [ 0, 1 ], [ 0, 0 ] ], - [ [ 1, 0 ], [ 0, 1 ] ], - [ [ 1, 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 1, 0 ] ], - [ [ 1, 1 ], [ 0, 1 ] ], - [ [ 0 ], [ 0, 0 ] ], - [ [ 0 ], [ 0, 1 ] ], - [ [ 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 0 ] ], - [ [ 1 ], [ 0, 1 ] ], - [ [ 1 ], [ 1, 0 ] ], - [ [ 1 ], [ 8, 0 ] ], - [ [ 8, 1, 6, 1 ], [ 0, 1, 5 ] ], - [ [ 8, 0, 6, 1 ], [ 1, 5 ] ] - ]; - - expected = [ - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 1, 0 ], - [ 8, 0 ], - [ 8, 0, 6, 5 ], - [ 8, 0, 6, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (no shapes)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [] - ]; - - expected = [ - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty shapes (i.e., zero-dimensional array broadcasting))', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [] ], - [ [], [] ], - [ [], [], [] ], - [ [], [ 0 ] ], - [ [ 0 ], [] ], - [ [], [ 0, 0 ] ], - [ [ 0, 0 ], [] ], - [ [], [ 1, 0 ] ], - [ [], [ 0, 1 ] ], - [ [], [ 3, 3 ] ], - [ [], [ 3, 3 ], [] ] - ]; - - expected = [ - [], - [], - [], - [ 0 ], - [ 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 3, 3 ], - [ 3, 3 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (single shape)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 7 ] ], - [ [ 1, 1 ] ], - [ [ 5, 6, 1 ] ] - ]; - - expected = [ - [ 7 ], - [ 1, 1 ], - [ 5, 6, 1 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function returns `null` if provided incompatible shapes', function test( t ) { - var actual; - var values; - var i; - - values = [ - [ [ 3 ], [ 4 ] ], - [ [ 2, 3 ], [ 2 ] ], - [ [ 3 ], [ 3 ], [ 4 ] ], - [ [ 1, 3, 4 ], [ 2, 3, 3 ] ], - [ [ 1, 2 ], [ 3, 1 ], [ 3, 2 ], [ 10, 5 ] ], - [ [ 2 ], [ 2, 3 ] ], - [ [ 2 ], [ 2 ], [ 2 ], [ 2 ], [ 3 ], [ 3 ], [ 3 ], [ 3 ] ], - [ [ 9, 0, 9 ], [ 0, 9, 0 ] ], - [ [ 9, 9, 9 ], [ 0, 9, 9 ] ], - [ [ 9, 0, 9 ], [ 9, 9, 9 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 0 ] ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.strictEqual( actual, null, 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); From 20354e47452806210a0e16360f045a0eb8e4e68d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 3 Oct 2024 02:06:10 +0000 Subject: [PATCH 126/158] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 4585eee..ea20c7c 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,8 @@ }, "dependencies": { "@stdlib/types": "^0.4.1", - "@stdlib/utils-library-manifest": "^0.2.2" + "@stdlib/utils-library-manifest": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, "devDependencies": { "@stdlib/string-left-pad": "^0.2.2", @@ -84,4 +85,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From adb418bb60173ec5b093982a90a7b473810cf479 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 3 Oct 2024 02:08:45 +0000 Subject: [PATCH 127/158] Remove files --- browser.js | 3 - browser.js.map | 1 - index.js | 3 - index.js.map | 1 - stats_browser.html | 4842 -------------------------------------------- stats_node.html | 4842 -------------------------------------------- 6 files changed, 9692 deletions(-) delete mode 100644 browser.js delete mode 100644 browser.js.map delete mode 100644 index.js delete mode 100644 index.js.map delete mode 100644 stats_browser.html delete mode 100644 stats_node.html diff --git a/browser.js b/browser.js deleted file mode 100644 index 44a8074..0000000 --- a/browser.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); -//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map deleted file mode 100644 index aa4b2bb..0000000 --- a/browser.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"browser.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/index.js b/index.js deleted file mode 100644 index d225eb4..0000000 --- a/index.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); -//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map deleted file mode 100644 index 0c02c0f..0000000 --- a/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/stats_browser.html b/stats_browser.html deleted file mode 100644 index 2f35700..0000000 --- a/stats_browser.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - diff --git a/stats_node.html b/stats_node.html deleted file mode 100644 index c264c7d..0000000 --- a/stats_node.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 1bed613d613fbd2913345c3c2a401012f3a8a72b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 3 Oct 2024 02:09:00 +0000 Subject: [PATCH 128/158] 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 | 242 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 178 +- SECURITY.md | 5 - benchmark/benchmark.js | 112 - benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 149 - branches.md | 56 - browser.js | 3 + browser.js.map | 1 + dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 39 - docs/types/index.d.ts | 177 - docs/types/test.ts | 45 - examples/c/Makefile | 146 - examples/c/example.c | 50 - examples/index.js | 54 - .../stdlib/ndarray/base/broadcast_shapes.h | 40 - index.js | 3 + index.js.map | 1 + lib/index.js | 45 - lib/main.js | 256 - manifest.json | 38 - package.json | 58 +- src/main.c | 118 - stats_browser.html | 4842 +++++++++++++++++ stats_node.html | 4842 +++++++++++++++++ test/dist/test.js | 33 - test/test.js | 230 - 52 files changed, 9729 insertions(+), 5370 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.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 branches.md create mode 100644 browser.js create mode 100644 browser.js.map 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/index.d.ts delete mode 100644 docs/types/test.ts delete mode 100644 examples/c/Makefile delete mode 100644 examples/c/example.c delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/broadcast_shapes.h create mode 100644 index.js create mode 100644 index.js.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 manifest.json delete mode 100644 src/main.c create mode 100644 stats_browser.html create mode 100644 stats_node.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 7f004ad..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 a07d970..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 7292af0..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: '0 12 * * 5' - - # 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 +``` -```javascript -var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); +If no recognized module system is present, access bundle contents via the global scope: + +```html + ``` #### broadcastShapes( shapes ) @@ -245,9 +251,14 @@ var sh = broadcastShapes( [ sh1, sh2 ] ); -```javascript -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); +```html + + + + + + + + ```
@@ -288,131 +304,7 @@ for ( i = 0; i < shapes.length; i++ ) { -* * * - -
- -## C APIs - - - -
- -
- - - - - -
- -### Usage - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -``` - -#### stdlib_ndarray_broadcast_shapes( M, \*\*shapes, \*ndims, \*out ) - -Broadcasts array shapes to a single shape. - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -int64_t N1 = 4; -int64_t sh1[] = { 8, 1, 6, 1 }; - -int64_t N2 = 3; -int64_t sh2[] = { 7, 1, 5 }; - -int64_t ndims[] = { N1, N2 }; -int64_t *shapes[] = { sh1, sh2 }; - -int64_t out[] = { 0, 0, 0, 0 }; -int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -if ( status != 0 ) { - // Handle error... -} -``` - -The function accepts the following arguments: - -- **M**: `[in] int64_t` number of shape arrays. -- **shapes**: `[in] int64_t**` array of shape arrays (dimensions). -- **ndims**: `[in] int64_t*` number of dimensions for each respective shape array. -- **out**: `[out] int64_t*` output shape array. - -```c -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], const int64_t ndims[], int64_t *out ); -``` - -If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). - -
- - - - - -
- -### Notes - -- Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. - -
- - - - - -
- -### Examples - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main( void ) { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} -``` - -
- - - -
- 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.js b/benchmark/benchmark.js deleted file mode 100644 index 6426216..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,112 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pkg = require( './../package.json' ).name; -var broadcastShapes = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::two_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ] ], - [ [ 3, 2 ], [ 3, 1 ] ], - [ [ 1, 1 ], [ 2, 2 ] ], - [ [ 1 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::three_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::four_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ], [ 8, 1, 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ], [ 1, 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ], [ 1, 1, 2, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ], [ 1 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ], [ 5, 1, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/c/Makefile b/benchmark/c/Makefile deleted file mode 100644 index 5dc545c..0000000 --- a/benchmark/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := benchmark.out - - -# RULES # - -#/ -# Compiles C source files. -# -# @param {string} SOURCE_FILES - list of C source files -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lpthread -lblas`) -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [C_COMPILER] - C compiler -# @param {string} [CFLAGS] - C compiler flags -# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} SOURCE_FILES - list of C source files -# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {(string|void)} LIBRARIES - list of libraries (e.g., `-lpthread -lblas`) -# @param {(string|void)} LIBPATH - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} CC - C compiler -# @param {string} CFLAGS - C compiler flags -# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled benchmarks. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/benchmark/c/benchmark.c b/benchmark/c/benchmark.c deleted file mode 100644 index 82d2be5..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,149 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "broadcast-shapes" -#define ITERATIONS 1000000 -#define REPEATS 3 - -/** -* Prints the TAP version. -*/ -static void print_version( void ) { - printf( "TAP version 13\n" ); -} - -/** -* Prints the TAP summary. -* -* @param total total number of tests -* @param passing total number of passing tests -*/ -static void print_summary( int total, int passing ) { - printf( "#\n" ); - printf( "1..%d\n", total ); // TAP plan - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); -} - -/** -* Prints benchmarks results. -* -* @param elapsed elapsed time in seconds -*/ -static void print_results( double elapsed ) { - double rate = (double)ITERATIONS / elapsed; - printf( " ---\n" ); - printf( " iterations: %d\n", ITERATIONS ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", rate ); - printf( " ...\n" ); -} - -/** -* Returns a clock time. -* -* @return clock time -*/ -static double tic( void ) { - struct timeval now; - gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; -} - -/** -* Generates a random number on the interval [0,1). -* -* @return random number -*/ -static double rand_double( void ) { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark( void ) { - double elapsed; - int8_t status; - double t; - int i; - - const int64_t sh1[] = { 8, 1, 6, 1 }; - const int64_t sh2[] = { 7, 1, 5 }; - - const int64_t ndims[] = { 4, 3 }; - const int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( out[ 0 ] != 8 ) { - printf( "unexpected result\n" ); - } - if ( out[ 1 ] != 7 ) { - printf( "unexpected result\n" ); - } - if ( out[ 2 ] != 6 ) { - printf( "unexpected result\n" ); - } - if ( out[ 3 ] != 5 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Main execution sequence. -*/ -int main( void ) { - double elapsed; - int i; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - for ( i = 0; i < REPEATS; i++ ) { - printf( "# c::native::%s::two_arrays\n", NAME ); - elapsed = benchmark(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", i+1 ); - } - print_summary( REPEATS, REPEATS ); -} diff --git a/branches.md b/branches.md deleted file mode 100644 index 79909c9..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes" -%% click B href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/blob/esm/README.md \ No newline at end of file diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..44a8074 --- /dev/null +++ b/browser.js @@ -0,0 +1,3 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map new file mode 100644 index 0000000..aa4b2bb --- /dev/null +++ b/browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"browser.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 87ea8b6..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import broadcastShapes from '../docs/types/index'; -export = broadcastShapes; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 625741a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var d=function(t,e){return function(){return e||t((e={exports:{}}).exports,e),e.exports}};var h=d(function(x,c){ -function g(t){var e,n,u,o,s,l,a,f,i,r,v;if(f=t.length,n=[],f===0)return n;if(o=t[0],i=o.length,f===1){for(r=0;ri&&(i=e[r]);for(r=0;r=0;){for(s=e[0]-i+r,s>=0?u=o[s]:u=1,v=1;v=0?a=t[v][l]:a=1,u===1){u=a;continue}if(!(a===1||u===a))return null}n[r]=u,r-=1}return n}c.exports=g -});var m=h();module.exports=m; -/** @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 db2949f..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = broadcastShapes;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast array shapes to a single shape.\n*\n* @module @stdlib/ndarray-base-broadcast-shapes\n*\n* @example\n* var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' );\n*\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\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,cAkLA,SAASC,EAAiBC,EAAS,CAClC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GAFAH,EAAIR,EAAO,OACXE,EAAM,CAAC,EACFM,IAAM,EACV,OAAON,EAMR,GAJAE,EAAKJ,EAAQ,CAAE,EACfS,EAAIL,EAAG,OAGFI,IAAM,EAAI,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAI,KAAME,EAAIM,CAAE,CAAE,EAEnB,OAAOR,CACR,CAGA,IADAD,EAAQ,CAAEQ,CAAE,EACNC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAM,KAAMD,EAAQU,CAAE,EAAE,MAAO,EAC1BT,EAAOS,CAAE,EAAID,IACjBA,EAAIR,EAAOS,CAAE,GAIf,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAI,KAAM,CAAE,EAIb,IADAQ,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IANAL,EAAKJ,EAAO,CAAE,EAAIQ,EAAIC,EACjBL,GAAM,EACVF,EAAMC,EAAIC,CAAG,EAEbF,EAAM,EAEDQ,EAAI,EAAGA,EAAIH,EAAGG,IAAM,CAOzB,GANAL,EAAKL,EAAOU,CAAE,EAAIF,EAAIC,EACjBJ,GAAM,EACVC,EAAIP,EAAQW,CAAE,EAAGL,CAAG,EAEpBC,EAAI,EAEAJ,IAAQ,EAAI,CAChBA,EAAMI,EACN,QACD,CACA,GAAK,EAAAA,IAAM,GAAKJ,IAAQI,GAKxB,OAAO,IACR,CACAL,EAAKQ,CAAE,EAAIP,EACXO,GAAK,CACN,CACA,OAAOR,CACR,CAKAJ,EAAO,QAAUC,ICxNjB,IAAIa,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "broadcastShapes", "shapes", "ndims", "out", "dim", "sh", "n1", "n2", "d", "M", "N", "i", "j", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f1d92f6..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,39 +0,0 @@ - -{{alias}}( shapes ) - Broadcasts array shapes to a single shape. - - Two respective dimensions in two shape arrays are compatible if - - 1. the dimensions are equal. - 2. one dimension is `1`. - - The function returns `null` if provided incompatible shapes (i.e., shapes - which cannot be broadcast with one another). - - Parameters - ---------- - shapes: Array - Array of shape arrays. - - Returns - ------- - out: Array|null - Broadcast shape. - - Examples - -------- - // Compatible shapes: - > var sh1 = [ 8, 1, 6, 1 ]; - > var sh2 = [ 7, 1, 5 ]; - > var sh = {{alias}}( [ sh1, sh2 ] ) - [ 8, 7, 6, 5 ] - - // Incompatible shapes: - > sh1 = [ 3, 2 ]; - > sh1 = [ 2, 3 ]; - > sh = {{alias}}( [ sh1, sh2 ] ) - null - - See Also - -------- - diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts deleted file mode 100644 index c2702cf..0000000 --- a/docs/types/index.d.ts +++ /dev/null @@ -1,177 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ArrayLike } from '@stdlib/types/array'; - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param shapes - array shapes -* @returns broadcast shape -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -declare function broadcastShapes( shapes: ArrayLike> ): ArrayLike; - - -// EXPORTS // - -export = broadcastShapes; diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 2886539..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 broadcastShapes = require( './index' ); - - -// TESTS // - -// The function returns an array of numbers... -{ - broadcastShapes( [ [ 1, 2 ], [ 2, 2 ] ] ); // $ExpectType ArrayLike -} - -// The compiler throws an error if the function is not provided an array-like object containing array-like objects containing numbers... -{ - broadcastShapes( '5' ); // $ExpectError - broadcastShapes( 5 ); // $ExpectError - broadcastShapes( true ); // $ExpectError - broadcastShapes( false ); // $ExpectError - broadcastShapes( null ); // $ExpectError - broadcastShapes( {} ); // $ExpectError - broadcastShapes( [ '5' ] ); // $ExpectError - broadcastShapes( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - broadcastShapes(); // $ExpectError - broadcastShapes( [ [ 1, 2, 3 ] ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/c/Makefile b/examples/c/Makefile deleted file mode 100644 index 70c91f4..0000000 --- a/examples/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := example.out - - -# RULES # - -#/ -# Compiles source files. -# -# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) -# @param {string} [CFLAGS] - C compiler options -# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) -# @param {string} [SOURCE_FILES] - list of source files -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} CC - C compiler (e.g., `gcc`) -# @param {string} CFLAGS - C compiler options -# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) -# @param {string} SOURCE_FILES - list of source files -# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) -# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled examples. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/examples/c/example.c b/examples/c/example.c deleted file mode 100644 index 4bc54d5..0000000 --- a/examples/c/example.c +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main( void ) { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 28811f9..0000000 --- a/examples/index.js +++ /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. -*/ - -'use strict'; - -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( './../lib' ); - -var shapes; -var out; -var sh; -var i; -var j; - -function shape2string( shape ) { - return lpad( shape.join( ' x ' ), 20, ' ' ); -} - -shapes = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] -]; - -for ( i = 0; i < shapes.length; i++ ) { - sh = shapes[ i ]; - for ( j = 0; j < sh.length; j++ ) { - console.log( shape2string( sh[ j ] ) ); - } - console.log( lpad( '', 20, '-' ) ); - - out = broadcastShapes( sh ); - console.log( shape2string( out )+'\n' ); -} diff --git a/include/stdlib/ndarray/base/broadcast_shapes.h b/include/stdlib/ndarray/base/broadcast_shapes.h deleted file mode 100644 index e23dce1..0000000 --- a/include/stdlib/ndarray/base/broadcast_shapes.h +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#ifndef STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H -#define STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H - -#include - -/* -* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. -*/ -#ifdef __cplusplus -extern "C" { -#endif - -/** -* Broadcasts array shapes to a single shape. -*/ -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H diff --git a/index.js b/index.js new file mode 100644 index 0000000..d225eb4 --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map new file mode 100644 index 0000000..0c02c0f --- /dev/null +++ b/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 0c9817e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Broadcast array shapes to a single shape. -* -* @module @stdlib/ndarray-base-broadcast-shapes -* -* @example -* var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); -* -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -*/ - -// 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 8558e60..0000000 --- a/lib/main.js +++ /dev/null @@ -1,256 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param {Array} shapes - array of shape arrays -* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`) -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [ 8, 0, 1, 6, 1 ], -* [ 8, 8, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -function broadcastShapes( shapes ) { - var ndims; - var out; - var dim; - var sh; - var n1; - var n2; - var d; - var M; - var N; - var i; - var j; - - M = shapes.length; - out = []; - if ( M === 0 ) { - return out; - } - sh = shapes[ 0 ]; - N = sh.length; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M === 1 ) { - // Need to manually copy to output shape, as shapes could be array-like objects... - for ( i = 0; i < N; i++ ) { - out.push( sh[ i ] ); - } - return out; - } - // Determine the maximum dimensionality... - ndims = [ N ]; - for ( i = 1; i < M; i++ ) { - ndims.push( shapes[ i ].length ); - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Initialize the output array... - for ( i = 0; i < N; i++ ) { - out.push( 0 ); - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim === 1 ) { - dim = d; - continue; - } - if ( d === 1 || dim === d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return null; - } - out[ i ] = dim; - i -= 1; - } - return out; -} - - -// EXPORTS // - -module.exports = broadcastShapes; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 890a937..0000000 --- a/manifest.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "options": {}, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [] - } - ] -} diff --git a/package.json b/package.json index ea20c7c..a9ff889 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,7 @@ "version": "0.2.2", "description": "Broadcast array shapes to a single shape.", "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", - "include": "./include", - "lib": "./lib", - "src": "./src", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "main": "./index.js", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,33 +12,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/types": "^0.4.1", - "@stdlib/utils-library-manifest": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/string-left-pad": "^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", "stdtypes", @@ -80,9 +27,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/src/main.c b/src/main.c deleted file mode 100644 index ca983c8..0000000 --- a/src/main.c +++ /dev/null @@ -1,118 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). -* -* - Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. -* -* @param M number of array shapes -* @param shapes pointer to an array containing shape arrays -* @param ndims array containing the number of dimensions for (i.e., length of) each respective shape array -* @param out pointer to output array -* @return status -* -* @example -* #include "stdlib/ndarray/base/broadcast_shapes.h" -* #include -* -* int64_t N1 = 4; -* int64_t sh1[] = { 8, 1, 6, 1 }; -* -* int64_t N2 = 3; -* int64_t sh2[] = { 7, 1, 5 }; -* -* int64_t ndims[] = { N1, N2 }; -* int64_t *shapes[] = { sh1, sh2 }; -* -* int64_t out[] = { 0, 0, 0, 0 }; -* int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -*/ -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], const int64_t ndims[], int64_t *out ) { - int64_t dim; - int64_t *sh; - int64_t n1; - int64_t n2; - int64_t d; - int64_t N; - int64_t i; - int64_t j; - - if ( M == 0 ) { - return 0; - } - sh = shapes[ 0 ]; - N = ndims[ 0 ]; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M == 1 ) { - for ( i = 0; i < N; i++ ) { - out[ i ] = sh[ i ]; - } - return 0; - } - // Determine the maximum dimensionality... - for ( i = 1; i < M; i++ ) { - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim == 1 ) { - dim = d; - continue; - } - if ( d == 1 || dim == d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return -1; - } - out[ i ] = dim; - i -= 1; - } - return 0; -} diff --git a/stats_browser.html b/stats_browser.html new file mode 100644 index 0000000..2f35700 --- /dev/null +++ b/stats_browser.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/stats_node.html b/stats_node.html new file mode 100644 index 0000000..c264c7d --- /dev/null +++ b/stats_node.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 63f703c..0000000 --- a/test/test.js +++ /dev/null @@ -1,230 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var broadcastShapes = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastShapes, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] - ]; - - expected = [ - [ 1, 2 ], - [ 3, 4 ], - [ 5, 6, 7 ], - [ 3, 3 ], - [ 3 ], - [ 3, 2 ], - [ 2, 3 ], - [ 1, 2 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty dims)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 0 ], [ 0, 0 ] ], - [ [ 0, 1 ], [ 0, 0 ] ], - [ [ 1, 0 ], [ 0, 1 ] ], - [ [ 1, 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 1, 0 ] ], - [ [ 1, 1 ], [ 0, 1 ] ], - [ [ 0 ], [ 0, 0 ] ], - [ [ 0 ], [ 0, 1 ] ], - [ [ 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 0 ] ], - [ [ 1 ], [ 0, 1 ] ], - [ [ 1 ], [ 1, 0 ] ], - [ [ 1 ], [ 8, 0 ] ], - [ [ 8, 1, 6, 1 ], [ 0, 1, 5 ] ], - [ [ 8, 0, 6, 1 ], [ 1, 5 ] ] - ]; - - expected = [ - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 1, 0 ], - [ 8, 0 ], - [ 8, 0, 6, 5 ], - [ 8, 0, 6, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (no shapes)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [] - ]; - - expected = [ - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty shapes (i.e., zero-dimensional array broadcasting))', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [] ], - [ [], [] ], - [ [], [], [] ], - [ [], [ 0 ] ], - [ [ 0 ], [] ], - [ [], [ 0, 0 ] ], - [ [ 0, 0 ], [] ], - [ [], [ 1, 0 ] ], - [ [], [ 0, 1 ] ], - [ [], [ 3, 3 ] ], - [ [], [ 3, 3 ], [] ] - ]; - - expected = [ - [], - [], - [], - [ 0 ], - [ 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 3, 3 ], - [ 3, 3 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (single shape)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 7 ] ], - [ [ 1, 1 ] ], - [ [ 5, 6, 1 ] ] - ]; - - expected = [ - [ 7 ], - [ 1, 1 ], - [ 5, 6, 1 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function returns `null` if provided incompatible shapes', function test( t ) { - var actual; - var values; - var i; - - values = [ - [ [ 3 ], [ 4 ] ], - [ [ 2, 3 ], [ 2 ] ], - [ [ 3 ], [ 3 ], [ 4 ] ], - [ [ 1, 3, 4 ], [ 2, 3, 3 ] ], - [ [ 1, 2 ], [ 3, 1 ], [ 3, 2 ], [ 10, 5 ] ], - [ [ 2 ], [ 2, 3 ] ], - [ [ 2 ], [ 2 ], [ 2 ], [ 2 ], [ 3 ], [ 3 ], [ 3 ], [ 3 ] ], - [ [ 9, 0, 9 ], [ 0, 9, 0 ] ], - [ [ 9, 9, 9 ], [ 0, 9, 9 ] ], - [ [ 9, 0, 9 ], [ 9, 9, 9 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 0 ] ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.strictEqual( actual, null, 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); From 6d707ef2e016cab801b0a141af75ff420b26c273 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Nov 2024 02:06:05 +0000 Subject: [PATCH 129/158] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 4585eee..ea20c7c 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,8 @@ }, "dependencies": { "@stdlib/types": "^0.4.1", - "@stdlib/utils-library-manifest": "^0.2.2" + "@stdlib/utils-library-manifest": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, "devDependencies": { "@stdlib/string-left-pad": "^0.2.2", @@ -84,4 +85,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From bc68b72976ac145594947debfece2b02b7f3d743 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Nov 2024 03:33:28 +0000 Subject: [PATCH 130/158] Remove files --- browser.js | 3 - browser.js.map | 1 - index.js | 3 - index.js.map | 1 - stats_browser.html | 4842 -------------------------------------------- stats_node.html | 4842 -------------------------------------------- 6 files changed, 9692 deletions(-) delete mode 100644 browser.js delete mode 100644 browser.js.map delete mode 100644 index.js delete mode 100644 index.js.map delete mode 100644 stats_browser.html delete mode 100644 stats_node.html diff --git a/browser.js b/browser.js deleted file mode 100644 index 44a8074..0000000 --- a/browser.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); -//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map deleted file mode 100644 index aa4b2bb..0000000 --- a/browser.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"browser.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/index.js b/index.js deleted file mode 100644 index d225eb4..0000000 --- a/index.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); -//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map deleted file mode 100644 index 0c02c0f..0000000 --- a/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/stats_browser.html b/stats_browser.html deleted file mode 100644 index 2f35700..0000000 --- a/stats_browser.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - diff --git a/stats_node.html b/stats_node.html deleted file mode 100644 index c264c7d..0000000 --- a/stats_node.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From e568ef997ca8a88b2e2ebc3d3d01af0ad8ceb75f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Nov 2024 03:33:40 +0000 Subject: [PATCH 131/158] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 242 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 178 +- SECURITY.md | 5 - benchmark/benchmark.js | 112 - benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 149 - branches.md | 56 - browser.js | 3 + browser.js.map | 1 + dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 39 - docs/types/index.d.ts | 177 - docs/types/test.ts | 45 - examples/c/Makefile | 146 - examples/c/example.c | 50 - examples/index.js | 54 - .../stdlib/ndarray/base/broadcast_shapes.h | 40 - index.js | 3 + index.js.map | 1 + lib/index.js | 45 - lib/main.js | 256 - manifest.json | 38 - package.json | 58 +- src/main.c | 118 - stats_browser.html | 4842 +++++++++++++++++ stats_node.html | 4842 +++++++++++++++++ test/dist/test.js | 33 - test/test.js | 230 - 53 files changed, 9729 insertions(+), 5371 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.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 branches.md create mode 100644 browser.js create mode 100644 browser.js.map 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/index.d.ts delete mode 100644 docs/types/test.ts delete mode 100644 examples/c/Makefile delete mode 100644 examples/c/example.c delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/broadcast_shapes.h create mode 100644 index.js create mode 100644 index.js.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 manifest.json delete mode 100644 src/main.c create mode 100644 stats_browser.html create mode 100644 stats_node.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/.keepalive b/.github/.keepalive deleted file mode 100644 index e874e36..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-11-01T01:40:27.830Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 7f004ad..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 a07d970..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 7292af0..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: '0 12 * * 5' - - # 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 +``` -```javascript -var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); +If no recognized module system is present, access bundle contents via the global scope: + +```html + ``` #### broadcastShapes( shapes ) @@ -245,9 +251,14 @@ var sh = broadcastShapes( [ sh1, sh2 ] ); -```javascript -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); +```html + + + + + + + + ```
@@ -288,131 +304,7 @@ for ( i = 0; i < shapes.length; i++ ) { -* * * - -
- -## C APIs - - - -
- -
- - - - - -
- -### Usage - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -``` - -#### stdlib_ndarray_broadcast_shapes( M, \*\*shapes, \*ndims, \*out ) - -Broadcasts array shapes to a single shape. - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -int64_t N1 = 4; -int64_t sh1[] = { 8, 1, 6, 1 }; - -int64_t N2 = 3; -int64_t sh2[] = { 7, 1, 5 }; - -int64_t ndims[] = { N1, N2 }; -int64_t *shapes[] = { sh1, sh2 }; - -int64_t out[] = { 0, 0, 0, 0 }; -int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -if ( status != 0 ) { - // Handle error... -} -``` - -The function accepts the following arguments: - -- **M**: `[in] int64_t` number of shape arrays. -- **shapes**: `[in] int64_t**` array of shape arrays (dimensions). -- **ndims**: `[in] int64_t*` number of dimensions for each respective shape array. -- **out**: `[out] int64_t*` output shape array. - -```c -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], const int64_t ndims[], int64_t *out ); -``` - -If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). - -
- - - - - -
- -### Notes - -- Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. - -
- - - - - -
- -### Examples - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main( void ) { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} -``` - -
- - - -
- 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.js b/benchmark/benchmark.js deleted file mode 100644 index 6426216..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,112 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pkg = require( './../package.json' ).name; -var broadcastShapes = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::two_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ] ], - [ [ 3, 2 ], [ 3, 1 ] ], - [ [ 1, 1 ], [ 2, 2 ] ], - [ [ 1 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::three_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::four_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ], [ 8, 1, 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ], [ 1, 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ], [ 1, 1, 2, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ], [ 1 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ], [ 5, 1, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/c/Makefile b/benchmark/c/Makefile deleted file mode 100644 index 5dc545c..0000000 --- a/benchmark/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := benchmark.out - - -# RULES # - -#/ -# Compiles C source files. -# -# @param {string} SOURCE_FILES - list of C source files -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lpthread -lblas`) -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [C_COMPILER] - C compiler -# @param {string} [CFLAGS] - C compiler flags -# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} SOURCE_FILES - list of C source files -# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {(string|void)} LIBRARIES - list of libraries (e.g., `-lpthread -lblas`) -# @param {(string|void)} LIBPATH - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} CC - C compiler -# @param {string} CFLAGS - C compiler flags -# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled benchmarks. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/benchmark/c/benchmark.c b/benchmark/c/benchmark.c deleted file mode 100644 index 82d2be5..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,149 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "broadcast-shapes" -#define ITERATIONS 1000000 -#define REPEATS 3 - -/** -* Prints the TAP version. -*/ -static void print_version( void ) { - printf( "TAP version 13\n" ); -} - -/** -* Prints the TAP summary. -* -* @param total total number of tests -* @param passing total number of passing tests -*/ -static void print_summary( int total, int passing ) { - printf( "#\n" ); - printf( "1..%d\n", total ); // TAP plan - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); -} - -/** -* Prints benchmarks results. -* -* @param elapsed elapsed time in seconds -*/ -static void print_results( double elapsed ) { - double rate = (double)ITERATIONS / elapsed; - printf( " ---\n" ); - printf( " iterations: %d\n", ITERATIONS ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", rate ); - printf( " ...\n" ); -} - -/** -* Returns a clock time. -* -* @return clock time -*/ -static double tic( void ) { - struct timeval now; - gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; -} - -/** -* Generates a random number on the interval [0,1). -* -* @return random number -*/ -static double rand_double( void ) { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark( void ) { - double elapsed; - int8_t status; - double t; - int i; - - const int64_t sh1[] = { 8, 1, 6, 1 }; - const int64_t sh2[] = { 7, 1, 5 }; - - const int64_t ndims[] = { 4, 3 }; - const int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( out[ 0 ] != 8 ) { - printf( "unexpected result\n" ); - } - if ( out[ 1 ] != 7 ) { - printf( "unexpected result\n" ); - } - if ( out[ 2 ] != 6 ) { - printf( "unexpected result\n" ); - } - if ( out[ 3 ] != 5 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Main execution sequence. -*/ -int main( void ) { - double elapsed; - int i; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - for ( i = 0; i < REPEATS; i++ ) { - printf( "# c::native::%s::two_arrays\n", NAME ); - elapsed = benchmark(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", i+1 ); - } - print_summary( REPEATS, REPEATS ); -} diff --git a/branches.md b/branches.md deleted file mode 100644 index 79909c9..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes" -%% click B href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/blob/esm/README.md \ No newline at end of file diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..44a8074 --- /dev/null +++ b/browser.js @@ -0,0 +1,3 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map new file mode 100644 index 0000000..aa4b2bb --- /dev/null +++ b/browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"browser.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 87ea8b6..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import broadcastShapes from '../docs/types/index'; -export = broadcastShapes; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 625741a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var d=function(t,e){return function(){return e||t((e={exports:{}}).exports,e),e.exports}};var h=d(function(x,c){ -function g(t){var e,n,u,o,s,l,a,f,i,r,v;if(f=t.length,n=[],f===0)return n;if(o=t[0],i=o.length,f===1){for(r=0;ri&&(i=e[r]);for(r=0;r=0;){for(s=e[0]-i+r,s>=0?u=o[s]:u=1,v=1;v=0?a=t[v][l]:a=1,u===1){u=a;continue}if(!(a===1||u===a))return null}n[r]=u,r-=1}return n}c.exports=g -});var m=h();module.exports=m; -/** @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 db2949f..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = broadcastShapes;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast array shapes to a single shape.\n*\n* @module @stdlib/ndarray-base-broadcast-shapes\n*\n* @example\n* var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' );\n*\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\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,cAkLA,SAASC,EAAiBC,EAAS,CAClC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GAFAH,EAAIR,EAAO,OACXE,EAAM,CAAC,EACFM,IAAM,EACV,OAAON,EAMR,GAJAE,EAAKJ,EAAQ,CAAE,EACfS,EAAIL,EAAG,OAGFI,IAAM,EAAI,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAI,KAAME,EAAIM,CAAE,CAAE,EAEnB,OAAOR,CACR,CAGA,IADAD,EAAQ,CAAEQ,CAAE,EACNC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAM,KAAMD,EAAQU,CAAE,EAAE,MAAO,EAC1BT,EAAOS,CAAE,EAAID,IACjBA,EAAIR,EAAOS,CAAE,GAIf,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAI,KAAM,CAAE,EAIb,IADAQ,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IANAL,EAAKJ,EAAO,CAAE,EAAIQ,EAAIC,EACjBL,GAAM,EACVF,EAAMC,EAAIC,CAAG,EAEbF,EAAM,EAEDQ,EAAI,EAAGA,EAAIH,EAAGG,IAAM,CAOzB,GANAL,EAAKL,EAAOU,CAAE,EAAIF,EAAIC,EACjBJ,GAAM,EACVC,EAAIP,EAAQW,CAAE,EAAGL,CAAG,EAEpBC,EAAI,EAEAJ,IAAQ,EAAI,CAChBA,EAAMI,EACN,QACD,CACA,GAAK,EAAAA,IAAM,GAAKJ,IAAQI,GAKxB,OAAO,IACR,CACAL,EAAKQ,CAAE,EAAIP,EACXO,GAAK,CACN,CACA,OAAOR,CACR,CAKAJ,EAAO,QAAUC,ICxNjB,IAAIa,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "broadcastShapes", "shapes", "ndims", "out", "dim", "sh", "n1", "n2", "d", "M", "N", "i", "j", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f1d92f6..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,39 +0,0 @@ - -{{alias}}( shapes ) - Broadcasts array shapes to a single shape. - - Two respective dimensions in two shape arrays are compatible if - - 1. the dimensions are equal. - 2. one dimension is `1`. - - The function returns `null` if provided incompatible shapes (i.e., shapes - which cannot be broadcast with one another). - - Parameters - ---------- - shapes: Array - Array of shape arrays. - - Returns - ------- - out: Array|null - Broadcast shape. - - Examples - -------- - // Compatible shapes: - > var sh1 = [ 8, 1, 6, 1 ]; - > var sh2 = [ 7, 1, 5 ]; - > var sh = {{alias}}( [ sh1, sh2 ] ) - [ 8, 7, 6, 5 ] - - // Incompatible shapes: - > sh1 = [ 3, 2 ]; - > sh1 = [ 2, 3 ]; - > sh = {{alias}}( [ sh1, sh2 ] ) - null - - See Also - -------- - diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts deleted file mode 100644 index c2702cf..0000000 --- a/docs/types/index.d.ts +++ /dev/null @@ -1,177 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ArrayLike } from '@stdlib/types/array'; - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param shapes - array shapes -* @returns broadcast shape -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -declare function broadcastShapes( shapes: ArrayLike> ): ArrayLike; - - -// EXPORTS // - -export = broadcastShapes; diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 2886539..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 broadcastShapes = require( './index' ); - - -// TESTS // - -// The function returns an array of numbers... -{ - broadcastShapes( [ [ 1, 2 ], [ 2, 2 ] ] ); // $ExpectType ArrayLike -} - -// The compiler throws an error if the function is not provided an array-like object containing array-like objects containing numbers... -{ - broadcastShapes( '5' ); // $ExpectError - broadcastShapes( 5 ); // $ExpectError - broadcastShapes( true ); // $ExpectError - broadcastShapes( false ); // $ExpectError - broadcastShapes( null ); // $ExpectError - broadcastShapes( {} ); // $ExpectError - broadcastShapes( [ '5' ] ); // $ExpectError - broadcastShapes( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - broadcastShapes(); // $ExpectError - broadcastShapes( [ [ 1, 2, 3 ] ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/c/Makefile b/examples/c/Makefile deleted file mode 100644 index 70c91f4..0000000 --- a/examples/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := example.out - - -# RULES # - -#/ -# Compiles source files. -# -# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) -# @param {string} [CFLAGS] - C compiler options -# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) -# @param {string} [SOURCE_FILES] - list of source files -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} CC - C compiler (e.g., `gcc`) -# @param {string} CFLAGS - C compiler options -# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) -# @param {string} SOURCE_FILES - list of source files -# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) -# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled examples. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/examples/c/example.c b/examples/c/example.c deleted file mode 100644 index 4bc54d5..0000000 --- a/examples/c/example.c +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main( void ) { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 28811f9..0000000 --- a/examples/index.js +++ /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. -*/ - -'use strict'; - -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( './../lib' ); - -var shapes; -var out; -var sh; -var i; -var j; - -function shape2string( shape ) { - return lpad( shape.join( ' x ' ), 20, ' ' ); -} - -shapes = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] -]; - -for ( i = 0; i < shapes.length; i++ ) { - sh = shapes[ i ]; - for ( j = 0; j < sh.length; j++ ) { - console.log( shape2string( sh[ j ] ) ); - } - console.log( lpad( '', 20, '-' ) ); - - out = broadcastShapes( sh ); - console.log( shape2string( out )+'\n' ); -} diff --git a/include/stdlib/ndarray/base/broadcast_shapes.h b/include/stdlib/ndarray/base/broadcast_shapes.h deleted file mode 100644 index e23dce1..0000000 --- a/include/stdlib/ndarray/base/broadcast_shapes.h +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#ifndef STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H -#define STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H - -#include - -/* -* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. -*/ -#ifdef __cplusplus -extern "C" { -#endif - -/** -* Broadcasts array shapes to a single shape. -*/ -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H diff --git a/index.js b/index.js new file mode 100644 index 0000000..d225eb4 --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map new file mode 100644 index 0000000..0c02c0f --- /dev/null +++ b/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 0c9817e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Broadcast array shapes to a single shape. -* -* @module @stdlib/ndarray-base-broadcast-shapes -* -* @example -* var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); -* -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -*/ - -// 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 8558e60..0000000 --- a/lib/main.js +++ /dev/null @@ -1,256 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param {Array} shapes - array of shape arrays -* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`) -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [ 8, 0, 1, 6, 1 ], -* [ 8, 8, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -function broadcastShapes( shapes ) { - var ndims; - var out; - var dim; - var sh; - var n1; - var n2; - var d; - var M; - var N; - var i; - var j; - - M = shapes.length; - out = []; - if ( M === 0 ) { - return out; - } - sh = shapes[ 0 ]; - N = sh.length; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M === 1 ) { - // Need to manually copy to output shape, as shapes could be array-like objects... - for ( i = 0; i < N; i++ ) { - out.push( sh[ i ] ); - } - return out; - } - // Determine the maximum dimensionality... - ndims = [ N ]; - for ( i = 1; i < M; i++ ) { - ndims.push( shapes[ i ].length ); - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Initialize the output array... - for ( i = 0; i < N; i++ ) { - out.push( 0 ); - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim === 1 ) { - dim = d; - continue; - } - if ( d === 1 || dim === d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return null; - } - out[ i ] = dim; - i -= 1; - } - return out; -} - - -// EXPORTS // - -module.exports = broadcastShapes; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 890a937..0000000 --- a/manifest.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "options": {}, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [] - } - ] -} diff --git a/package.json b/package.json index ea20c7c..a9ff889 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,7 @@ "version": "0.2.2", "description": "Broadcast array shapes to a single shape.", "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", - "include": "./include", - "lib": "./lib", - "src": "./src", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "main": "./index.js", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,33 +12,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/types": "^0.4.1", - "@stdlib/utils-library-manifest": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/string-left-pad": "^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", "stdtypes", @@ -80,9 +27,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/src/main.c b/src/main.c deleted file mode 100644 index ca983c8..0000000 --- a/src/main.c +++ /dev/null @@ -1,118 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). -* -* - Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. -* -* @param M number of array shapes -* @param shapes pointer to an array containing shape arrays -* @param ndims array containing the number of dimensions for (i.e., length of) each respective shape array -* @param out pointer to output array -* @return status -* -* @example -* #include "stdlib/ndarray/base/broadcast_shapes.h" -* #include -* -* int64_t N1 = 4; -* int64_t sh1[] = { 8, 1, 6, 1 }; -* -* int64_t N2 = 3; -* int64_t sh2[] = { 7, 1, 5 }; -* -* int64_t ndims[] = { N1, N2 }; -* int64_t *shapes[] = { sh1, sh2 }; -* -* int64_t out[] = { 0, 0, 0, 0 }; -* int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -*/ -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], const int64_t ndims[], int64_t *out ) { - int64_t dim; - int64_t *sh; - int64_t n1; - int64_t n2; - int64_t d; - int64_t N; - int64_t i; - int64_t j; - - if ( M == 0 ) { - return 0; - } - sh = shapes[ 0 ]; - N = ndims[ 0 ]; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M == 1 ) { - for ( i = 0; i < N; i++ ) { - out[ i ] = sh[ i ]; - } - return 0; - } - // Determine the maximum dimensionality... - for ( i = 1; i < M; i++ ) { - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim == 1 ) { - dim = d; - continue; - } - if ( d == 1 || dim == d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return -1; - } - out[ i ] = dim; - i -= 1; - } - return 0; -} diff --git a/stats_browser.html b/stats_browser.html new file mode 100644 index 0000000..2f35700 --- /dev/null +++ b/stats_browser.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/stats_node.html b/stats_node.html new file mode 100644 index 0000000..c264c7d --- /dev/null +++ b/stats_node.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 63f703c..0000000 --- a/test/test.js +++ /dev/null @@ -1,230 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var broadcastShapes = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastShapes, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] - ]; - - expected = [ - [ 1, 2 ], - [ 3, 4 ], - [ 5, 6, 7 ], - [ 3, 3 ], - [ 3 ], - [ 3, 2 ], - [ 2, 3 ], - [ 1, 2 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty dims)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 0 ], [ 0, 0 ] ], - [ [ 0, 1 ], [ 0, 0 ] ], - [ [ 1, 0 ], [ 0, 1 ] ], - [ [ 1, 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 1, 0 ] ], - [ [ 1, 1 ], [ 0, 1 ] ], - [ [ 0 ], [ 0, 0 ] ], - [ [ 0 ], [ 0, 1 ] ], - [ [ 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 0 ] ], - [ [ 1 ], [ 0, 1 ] ], - [ [ 1 ], [ 1, 0 ] ], - [ [ 1 ], [ 8, 0 ] ], - [ [ 8, 1, 6, 1 ], [ 0, 1, 5 ] ], - [ [ 8, 0, 6, 1 ], [ 1, 5 ] ] - ]; - - expected = [ - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 1, 0 ], - [ 8, 0 ], - [ 8, 0, 6, 5 ], - [ 8, 0, 6, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (no shapes)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [] - ]; - - expected = [ - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty shapes (i.e., zero-dimensional array broadcasting))', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [] ], - [ [], [] ], - [ [], [], [] ], - [ [], [ 0 ] ], - [ [ 0 ], [] ], - [ [], [ 0, 0 ] ], - [ [ 0, 0 ], [] ], - [ [], [ 1, 0 ] ], - [ [], [ 0, 1 ] ], - [ [], [ 3, 3 ] ], - [ [], [ 3, 3 ], [] ] - ]; - - expected = [ - [], - [], - [], - [ 0 ], - [ 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 3, 3 ], - [ 3, 3 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (single shape)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 7 ] ], - [ [ 1, 1 ] ], - [ [ 5, 6, 1 ] ] - ]; - - expected = [ - [ 7 ], - [ 1, 1 ], - [ 5, 6, 1 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function returns `null` if provided incompatible shapes', function test( t ) { - var actual; - var values; - var i; - - values = [ - [ [ 3 ], [ 4 ] ], - [ [ 2, 3 ], [ 2 ] ], - [ [ 3 ], [ 3 ], [ 4 ] ], - [ [ 1, 3, 4 ], [ 2, 3, 3 ] ], - [ [ 1, 2 ], [ 3, 1 ], [ 3, 2 ], [ 10, 5 ] ], - [ [ 2 ], [ 2, 3 ] ], - [ [ 2 ], [ 2 ], [ 2 ], [ 2 ], [ 3 ], [ 3 ], [ 3 ], [ 3 ] ], - [ [ 9, 0, 9 ], [ 0, 9, 0 ] ], - [ [ 9, 9, 9 ], [ 0, 9, 9 ] ], - [ [ 9, 0, 9 ], [ 9, 9, 9 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 0 ] ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.strictEqual( actual, null, 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); From e8362146525708e11b7ceb3bdf3a111d0833e36e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Dec 2024 02:12:38 +0000 Subject: [PATCH 132/158] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 6259d77..dcdfdb6 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,8 @@ }, "dependencies": { "@stdlib/types": "^0.4.3", - "@stdlib/utils-library-manifest": "^0.2.2" + "@stdlib/utils-library-manifest": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, "devDependencies": { "@stdlib/string-left-pad": "^0.2.2", @@ -84,4 +85,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From b0a6d881527ab30f3c64f286944aabb1c433ba30 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Dec 2024 03:46:05 +0000 Subject: [PATCH 133/158] Remove files --- browser.js | 3 - browser.js.map | 1 - index.js | 3 - index.js.map | 1 - stats_browser.html | 4842 -------------------------------------------- stats_node.html | 4842 -------------------------------------------- 6 files changed, 9692 deletions(-) delete mode 100644 browser.js delete mode 100644 browser.js.map delete mode 100644 index.js delete mode 100644 index.js.map delete mode 100644 stats_browser.html delete mode 100644 stats_node.html diff --git a/browser.js b/browser.js deleted file mode 100644 index 44a8074..0000000 --- a/browser.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); -//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map deleted file mode 100644 index aa4b2bb..0000000 --- a/browser.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"browser.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/index.js b/index.js deleted file mode 100644 index d225eb4..0000000 --- a/index.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); -//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map deleted file mode 100644 index 0c02c0f..0000000 --- a/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/stats_browser.html b/stats_browser.html deleted file mode 100644 index 2f35700..0000000 --- a/stats_browser.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - diff --git a/stats_node.html b/stats_node.html deleted file mode 100644 index c264c7d..0000000 --- a/stats_node.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From d0a72549e22f2b7f9a466d4676b22e8a291fe6f4 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Dec 2024 03:46:23 +0000 Subject: [PATCH 134/158] 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 | 242 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 178 +- SECURITY.md | 5 - benchmark/benchmark.js | 112 - benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 149 - branches.md | 56 - browser.js | 3 + browser.js.map | 1 + dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 39 - docs/types/index.d.ts | 177 - docs/types/test.ts | 45 - examples/c/Makefile | 146 - examples/c/example.c | 50 - examples/index.js | 54 - .../stdlib/ndarray/base/broadcast_shapes.h | 40 - index.js | 3 + index.js.map | 1 + lib/index.js | 45 - lib/main.js | 256 - manifest.json | 38 - package.json | 58 +- src/main.c | 118 - stats_browser.html | 4842 +++++++++++++++++ stats_node.html | 4842 +++++++++++++++++ test/dist/test.js | 33 - test/test.js | 230 - 54 files changed, 9729 insertions(+), 5476 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.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 branches.md create mode 100644 browser.js create mode 100644 browser.js.map 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/index.d.ts delete mode 100644 docs/types/test.ts delete mode 100644 examples/c/Makefile delete mode 100644 examples/c/example.c delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/broadcast_shapes.h create mode 100644 index.js create mode 100644 index.js.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 manifest.json delete mode 100644 src/main.c create mode 100644 stats_browser.html create mode 100644 stats_node.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/.keepalive b/.github/.keepalive deleted file mode 100644 index 5eafbe2..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-12-01T01:46:58.277Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 7f004ad..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 a07d970..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 7292af0..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: '0 12 * * 5' - - # 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 +``` -```javascript -var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); +If no recognized module system is present, access bundle contents via the global scope: + +```html + ``` #### broadcastShapes( shapes ) @@ -245,9 +251,14 @@ var sh = broadcastShapes( [ sh1, sh2 ] ); -```javascript -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); +```html + + + + + + + + ```
@@ -288,131 +304,7 @@ for ( i = 0; i < shapes.length; i++ ) { -* * * - -
- -## C APIs - - - -
- -
- - - - - -
- -### Usage - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -``` - -#### stdlib_ndarray_broadcast_shapes( M, \*\*shapes, \*ndims, \*out ) - -Broadcasts array shapes to a single shape. - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -int64_t N1 = 4; -int64_t sh1[] = { 8, 1, 6, 1 }; - -int64_t N2 = 3; -int64_t sh2[] = { 7, 1, 5 }; - -int64_t ndims[] = { N1, N2 }; -int64_t *shapes[] = { sh1, sh2 }; - -int64_t out[] = { 0, 0, 0, 0 }; -int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -if ( status != 0 ) { - // Handle error... -} -``` - -The function accepts the following arguments: - -- **M**: `[in] int64_t` number of shape arrays. -- **shapes**: `[in] int64_t**` array of shape arrays (dimensions). -- **ndims**: `[in] int64_t*` number of dimensions for each respective shape array. -- **out**: `[out] int64_t*` output shape array. - -```c -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], const int64_t ndims[], int64_t *out ); -``` - -If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). - -
- - - - - -
- -### Notes - -- Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. - -
- - - - - -
- -### Examples - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main( void ) { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} -``` - -
- - - -
- 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.js b/benchmark/benchmark.js deleted file mode 100644 index 6426216..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,112 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pkg = require( './../package.json' ).name; -var broadcastShapes = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::two_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ] ], - [ [ 3, 2 ], [ 3, 1 ] ], - [ [ 1, 1 ], [ 2, 2 ] ], - [ [ 1 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::three_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::four_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ], [ 8, 1, 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ], [ 1, 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ], [ 1, 1, 2, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ], [ 1 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ], [ 5, 1, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/c/Makefile b/benchmark/c/Makefile deleted file mode 100644 index 5dc545c..0000000 --- a/benchmark/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := benchmark.out - - -# RULES # - -#/ -# Compiles C source files. -# -# @param {string} SOURCE_FILES - list of C source files -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lpthread -lblas`) -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [C_COMPILER] - C compiler -# @param {string} [CFLAGS] - C compiler flags -# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} SOURCE_FILES - list of C source files -# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {(string|void)} LIBRARIES - list of libraries (e.g., `-lpthread -lblas`) -# @param {(string|void)} LIBPATH - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} CC - C compiler -# @param {string} CFLAGS - C compiler flags -# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled benchmarks. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/benchmark/c/benchmark.c b/benchmark/c/benchmark.c deleted file mode 100644 index 82d2be5..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,149 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "broadcast-shapes" -#define ITERATIONS 1000000 -#define REPEATS 3 - -/** -* Prints the TAP version. -*/ -static void print_version( void ) { - printf( "TAP version 13\n" ); -} - -/** -* Prints the TAP summary. -* -* @param total total number of tests -* @param passing total number of passing tests -*/ -static void print_summary( int total, int passing ) { - printf( "#\n" ); - printf( "1..%d\n", total ); // TAP plan - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); -} - -/** -* Prints benchmarks results. -* -* @param elapsed elapsed time in seconds -*/ -static void print_results( double elapsed ) { - double rate = (double)ITERATIONS / elapsed; - printf( " ---\n" ); - printf( " iterations: %d\n", ITERATIONS ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", rate ); - printf( " ...\n" ); -} - -/** -* Returns a clock time. -* -* @return clock time -*/ -static double tic( void ) { - struct timeval now; - gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; -} - -/** -* Generates a random number on the interval [0,1). -* -* @return random number -*/ -static double rand_double( void ) { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark( void ) { - double elapsed; - int8_t status; - double t; - int i; - - const int64_t sh1[] = { 8, 1, 6, 1 }; - const int64_t sh2[] = { 7, 1, 5 }; - - const int64_t ndims[] = { 4, 3 }; - const int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( out[ 0 ] != 8 ) { - printf( "unexpected result\n" ); - } - if ( out[ 1 ] != 7 ) { - printf( "unexpected result\n" ); - } - if ( out[ 2 ] != 6 ) { - printf( "unexpected result\n" ); - } - if ( out[ 3 ] != 5 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Main execution sequence. -*/ -int main( void ) { - double elapsed; - int i; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - for ( i = 0; i < REPEATS; i++ ) { - printf( "# c::native::%s::two_arrays\n", NAME ); - elapsed = benchmark(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", i+1 ); - } - print_summary( REPEATS, REPEATS ); -} diff --git a/branches.md b/branches.md deleted file mode 100644 index 79909c9..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes" -%% click B href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/blob/esm/README.md \ No newline at end of file diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..44a8074 --- /dev/null +++ b/browser.js @@ -0,0 +1,3 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map new file mode 100644 index 0000000..aa4b2bb --- /dev/null +++ b/browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"browser.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 87ea8b6..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import broadcastShapes from '../docs/types/index'; -export = broadcastShapes; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 625741a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var d=function(t,e){return function(){return e||t((e={exports:{}}).exports,e),e.exports}};var h=d(function(x,c){ -function g(t){var e,n,u,o,s,l,a,f,i,r,v;if(f=t.length,n=[],f===0)return n;if(o=t[0],i=o.length,f===1){for(r=0;ri&&(i=e[r]);for(r=0;r=0;){for(s=e[0]-i+r,s>=0?u=o[s]:u=1,v=1;v=0?a=t[v][l]:a=1,u===1){u=a;continue}if(!(a===1||u===a))return null}n[r]=u,r-=1}return n}c.exports=g -});var m=h();module.exports=m; -/** @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 db2949f..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = broadcastShapes;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast array shapes to a single shape.\n*\n* @module @stdlib/ndarray-base-broadcast-shapes\n*\n* @example\n* var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' );\n*\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\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,cAkLA,SAASC,EAAiBC,EAAS,CAClC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GAFAH,EAAIR,EAAO,OACXE,EAAM,CAAC,EACFM,IAAM,EACV,OAAON,EAMR,GAJAE,EAAKJ,EAAQ,CAAE,EACfS,EAAIL,EAAG,OAGFI,IAAM,EAAI,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAI,KAAME,EAAIM,CAAE,CAAE,EAEnB,OAAOR,CACR,CAGA,IADAD,EAAQ,CAAEQ,CAAE,EACNC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAM,KAAMD,EAAQU,CAAE,EAAE,MAAO,EAC1BT,EAAOS,CAAE,EAAID,IACjBA,EAAIR,EAAOS,CAAE,GAIf,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAI,KAAM,CAAE,EAIb,IADAQ,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IANAL,EAAKJ,EAAO,CAAE,EAAIQ,EAAIC,EACjBL,GAAM,EACVF,EAAMC,EAAIC,CAAG,EAEbF,EAAM,EAEDQ,EAAI,EAAGA,EAAIH,EAAGG,IAAM,CAOzB,GANAL,EAAKL,EAAOU,CAAE,EAAIF,EAAIC,EACjBJ,GAAM,EACVC,EAAIP,EAAQW,CAAE,EAAGL,CAAG,EAEpBC,EAAI,EAEAJ,IAAQ,EAAI,CAChBA,EAAMI,EACN,QACD,CACA,GAAK,EAAAA,IAAM,GAAKJ,IAAQI,GAKxB,OAAO,IACR,CACAL,EAAKQ,CAAE,EAAIP,EACXO,GAAK,CACN,CACA,OAAOR,CACR,CAKAJ,EAAO,QAAUC,ICxNjB,IAAIa,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "broadcastShapes", "shapes", "ndims", "out", "dim", "sh", "n1", "n2", "d", "M", "N", "i", "j", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f1d92f6..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,39 +0,0 @@ - -{{alias}}( shapes ) - Broadcasts array shapes to a single shape. - - Two respective dimensions in two shape arrays are compatible if - - 1. the dimensions are equal. - 2. one dimension is `1`. - - The function returns `null` if provided incompatible shapes (i.e., shapes - which cannot be broadcast with one another). - - Parameters - ---------- - shapes: Array - Array of shape arrays. - - Returns - ------- - out: Array|null - Broadcast shape. - - Examples - -------- - // Compatible shapes: - > var sh1 = [ 8, 1, 6, 1 ]; - > var sh2 = [ 7, 1, 5 ]; - > var sh = {{alias}}( [ sh1, sh2 ] ) - [ 8, 7, 6, 5 ] - - // Incompatible shapes: - > sh1 = [ 3, 2 ]; - > sh1 = [ 2, 3 ]; - > sh = {{alias}}( [ sh1, sh2 ] ) - null - - See Also - -------- - diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts deleted file mode 100644 index c2702cf..0000000 --- a/docs/types/index.d.ts +++ /dev/null @@ -1,177 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ArrayLike } from '@stdlib/types/array'; - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param shapes - array shapes -* @returns broadcast shape -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -declare function broadcastShapes( shapes: ArrayLike> ): ArrayLike; - - -// EXPORTS // - -export = broadcastShapes; diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 2886539..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 broadcastShapes = require( './index' ); - - -// TESTS // - -// The function returns an array of numbers... -{ - broadcastShapes( [ [ 1, 2 ], [ 2, 2 ] ] ); // $ExpectType ArrayLike -} - -// The compiler throws an error if the function is not provided an array-like object containing array-like objects containing numbers... -{ - broadcastShapes( '5' ); // $ExpectError - broadcastShapes( 5 ); // $ExpectError - broadcastShapes( true ); // $ExpectError - broadcastShapes( false ); // $ExpectError - broadcastShapes( null ); // $ExpectError - broadcastShapes( {} ); // $ExpectError - broadcastShapes( [ '5' ] ); // $ExpectError - broadcastShapes( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - broadcastShapes(); // $ExpectError - broadcastShapes( [ [ 1, 2, 3 ] ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/c/Makefile b/examples/c/Makefile deleted file mode 100644 index 70c91f4..0000000 --- a/examples/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := example.out - - -# RULES # - -#/ -# Compiles source files. -# -# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) -# @param {string} [CFLAGS] - C compiler options -# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) -# @param {string} [SOURCE_FILES] - list of source files -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} CC - C compiler (e.g., `gcc`) -# @param {string} CFLAGS - C compiler options -# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) -# @param {string} SOURCE_FILES - list of source files -# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) -# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled examples. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/examples/c/example.c b/examples/c/example.c deleted file mode 100644 index 4bc54d5..0000000 --- a/examples/c/example.c +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main( void ) { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 28811f9..0000000 --- a/examples/index.js +++ /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. -*/ - -'use strict'; - -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( './../lib' ); - -var shapes; -var out; -var sh; -var i; -var j; - -function shape2string( shape ) { - return lpad( shape.join( ' x ' ), 20, ' ' ); -} - -shapes = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] -]; - -for ( i = 0; i < shapes.length; i++ ) { - sh = shapes[ i ]; - for ( j = 0; j < sh.length; j++ ) { - console.log( shape2string( sh[ j ] ) ); - } - console.log( lpad( '', 20, '-' ) ); - - out = broadcastShapes( sh ); - console.log( shape2string( out )+'\n' ); -} diff --git a/include/stdlib/ndarray/base/broadcast_shapes.h b/include/stdlib/ndarray/base/broadcast_shapes.h deleted file mode 100644 index e23dce1..0000000 --- a/include/stdlib/ndarray/base/broadcast_shapes.h +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#ifndef STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H -#define STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H - -#include - -/* -* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. -*/ -#ifdef __cplusplus -extern "C" { -#endif - -/** -* Broadcasts array shapes to a single shape. -*/ -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], int64_t ndims[], int64_t *out ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H diff --git a/index.js b/index.js new file mode 100644 index 0000000..d225eb4 --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map new file mode 100644 index 0000000..0c02c0f --- /dev/null +++ b/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 0c9817e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Broadcast array shapes to a single shape. -* -* @module @stdlib/ndarray-base-broadcast-shapes -* -* @example -* var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); -* -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -*/ - -// 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 8558e60..0000000 --- a/lib/main.js +++ /dev/null @@ -1,256 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param {Array} shapes - array of shape arrays -* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`) -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [ 8, 0, 1, 6, 1 ], -* [ 8, 8, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -function broadcastShapes( shapes ) { - var ndims; - var out; - var dim; - var sh; - var n1; - var n2; - var d; - var M; - var N; - var i; - var j; - - M = shapes.length; - out = []; - if ( M === 0 ) { - return out; - } - sh = shapes[ 0 ]; - N = sh.length; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M === 1 ) { - // Need to manually copy to output shape, as shapes could be array-like objects... - for ( i = 0; i < N; i++ ) { - out.push( sh[ i ] ); - } - return out; - } - // Determine the maximum dimensionality... - ndims = [ N ]; - for ( i = 1; i < M; i++ ) { - ndims.push( shapes[ i ].length ); - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Initialize the output array... - for ( i = 0; i < N; i++ ) { - out.push( 0 ); - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim === 1 ) { - dim = d; - continue; - } - if ( d === 1 || dim === d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return null; - } - out[ i ] = dim; - i -= 1; - } - return out; -} - - -// EXPORTS // - -module.exports = broadcastShapes; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 890a937..0000000 --- a/manifest.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "options": {}, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [] - } - ] -} diff --git a/package.json b/package.json index dcdfdb6..a9ff889 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,7 @@ "version": "0.2.2", "description": "Broadcast array shapes to a single shape.", "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", - "include": "./include", - "lib": "./lib", - "src": "./src", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "main": "./index.js", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,33 +12,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/types": "^0.4.3", - "@stdlib/utils-library-manifest": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/string-left-pad": "^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", "stdtypes", @@ -80,9 +27,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/src/main.c b/src/main.c deleted file mode 100644 index ca983c8..0000000 --- a/src/main.c +++ /dev/null @@ -1,118 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). -* -* - Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. -* -* @param M number of array shapes -* @param shapes pointer to an array containing shape arrays -* @param ndims array containing the number of dimensions for (i.e., length of) each respective shape array -* @param out pointer to output array -* @return status -* -* @example -* #include "stdlib/ndarray/base/broadcast_shapes.h" -* #include -* -* int64_t N1 = 4; -* int64_t sh1[] = { 8, 1, 6, 1 }; -* -* int64_t N2 = 3; -* int64_t sh2[] = { 7, 1, 5 }; -* -* int64_t ndims[] = { N1, N2 }; -* int64_t *shapes[] = { sh1, sh2 }; -* -* int64_t out[] = { 0, 0, 0, 0 }; -* int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -*/ -int8_t stdlib_ndarray_broadcast_shapes( int64_t M, int64_t *shapes[], const int64_t ndims[], int64_t *out ) { - int64_t dim; - int64_t *sh; - int64_t n1; - int64_t n2; - int64_t d; - int64_t N; - int64_t i; - int64_t j; - - if ( M == 0 ) { - return 0; - } - sh = shapes[ 0 ]; - N = ndims[ 0 ]; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M == 1 ) { - for ( i = 0; i < N; i++ ) { - out[ i ] = sh[ i ]; - } - return 0; - } - // Determine the maximum dimensionality... - for ( i = 1; i < M; i++ ) { - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim == 1 ) { - dim = d; - continue; - } - if ( d == 1 || dim == d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return -1; - } - out[ i ] = dim; - i -= 1; - } - return 0; -} diff --git a/stats_browser.html b/stats_browser.html new file mode 100644 index 0000000..2f35700 --- /dev/null +++ b/stats_browser.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/stats_node.html b/stats_node.html new file mode 100644 index 0000000..c264c7d --- /dev/null +++ b/stats_node.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 63f703c..0000000 --- a/test/test.js +++ /dev/null @@ -1,230 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var broadcastShapes = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastShapes, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] - ]; - - expected = [ - [ 1, 2 ], - [ 3, 4 ], - [ 5, 6, 7 ], - [ 3, 3 ], - [ 3 ], - [ 3, 2 ], - [ 2, 3 ], - [ 1, 2 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty dims)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 0 ], [ 0, 0 ] ], - [ [ 0, 1 ], [ 0, 0 ] ], - [ [ 1, 0 ], [ 0, 1 ] ], - [ [ 1, 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 1, 0 ] ], - [ [ 1, 1 ], [ 0, 1 ] ], - [ [ 0 ], [ 0, 0 ] ], - [ [ 0 ], [ 0, 1 ] ], - [ [ 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 0 ] ], - [ [ 1 ], [ 0, 1 ] ], - [ [ 1 ], [ 1, 0 ] ], - [ [ 1 ], [ 8, 0 ] ], - [ [ 8, 1, 6, 1 ], [ 0, 1, 5 ] ], - [ [ 8, 0, 6, 1 ], [ 1, 5 ] ] - ]; - - expected = [ - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 1, 0 ], - [ 8, 0 ], - [ 8, 0, 6, 5 ], - [ 8, 0, 6, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (no shapes)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [] - ]; - - expected = [ - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty shapes (i.e., zero-dimensional array broadcasting))', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [] ], - [ [], [] ], - [ [], [], [] ], - [ [], [ 0 ] ], - [ [ 0 ], [] ], - [ [], [ 0, 0 ] ], - [ [ 0, 0 ], [] ], - [ [], [ 1, 0 ] ], - [ [], [ 0, 1 ] ], - [ [], [ 3, 3 ] ], - [ [], [ 3, 3 ], [] ] - ]; - - expected = [ - [], - [], - [], - [ 0 ], - [ 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 3, 3 ], - [ 3, 3 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (single shape)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 7 ] ], - [ [ 1, 1 ] ], - [ [ 5, 6, 1 ] ] - ]; - - expected = [ - [ 7 ], - [ 1, 1 ], - [ 5, 6, 1 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function returns `null` if provided incompatible shapes', function test( t ) { - var actual; - var values; - var i; - - values = [ - [ [ 3 ], [ 4 ] ], - [ [ 2, 3 ], [ 2 ] ], - [ [ 3 ], [ 3 ], [ 4 ] ], - [ [ 1, 3, 4 ], [ 2, 3, 3 ] ], - [ [ 1, 2 ], [ 3, 1 ], [ 3, 2 ], [ 10, 5 ] ], - [ [ 2 ], [ 2, 3 ] ], - [ [ 2 ], [ 2 ], [ 2 ], [ 2 ], [ 3 ], [ 3 ], [ 3 ], [ 3 ] ], - [ [ 9, 0, 9 ], [ 0, 9, 0 ] ], - [ [ 9, 9, 9 ], [ 0, 9, 9 ] ], - [ [ 9, 0, 9 ], [ 9, 9, 9 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 0 ] ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.strictEqual( actual, null, 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); From 062466eba7c65df783272c5969efd7cf631a218d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 2 Dec 2024 00:11:51 +0000 Subject: [PATCH 135/158] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 6259d77..dcdfdb6 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,8 @@ }, "dependencies": { "@stdlib/types": "^0.4.3", - "@stdlib/utils-library-manifest": "^0.2.2" + "@stdlib/utils-library-manifest": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, "devDependencies": { "@stdlib/string-left-pad": "^0.2.2", @@ -84,4 +85,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From 168671a4855169a31d11e01700d0fa6839e536dc Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 2 Dec 2024 00:12:18 +0000 Subject: [PATCH 136/158] Remove files --- browser.js | 3 - browser.js.map | 1 - index.js | 3 - index.js.map | 1 - stats_browser.html | 4842 -------------------------------------------- stats_node.html | 4842 -------------------------------------------- 6 files changed, 9692 deletions(-) delete mode 100644 browser.js delete mode 100644 browser.js.map delete mode 100644 index.js delete mode 100644 index.js.map delete mode 100644 stats_browser.html delete mode 100644 stats_node.html diff --git a/browser.js b/browser.js deleted file mode 100644 index 44a8074..0000000 --- a/browser.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); -//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map deleted file mode 100644 index aa4b2bb..0000000 --- a/browser.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"browser.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/index.js b/index.js deleted file mode 100644 index d225eb4..0000000 --- a/index.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); -//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map deleted file mode 100644 index 0c02c0f..0000000 --- a/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/stats_browser.html b/stats_browser.html deleted file mode 100644 index 2f35700..0000000 --- a/stats_browser.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - diff --git a/stats_node.html b/stats_node.html deleted file mode 100644 index c264c7d..0000000 --- a/stats_node.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From acb2c086db6b498870ef538310d03e45e31c5adf Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 2 Dec 2024 00:12:34 +0000 Subject: [PATCH 137/158] 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 - .github/workflows/test_published_package.yml | 105 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 243 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 178 +- SECURITY.md | 5 - benchmark/benchmark.js | 112 - benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 149 - branches.md | 56 - browser.js | 3 + browser.js.map | 1 + dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 39 - docs/types/index.d.ts | 177 - docs/types/test.ts | 45 - examples/c/Makefile | 146 - examples/c/example.c | 50 - examples/index.js | 54 - .../stdlib/ndarray/base/broadcast_shapes.h | 40 - index.js | 3 + index.js.map | 1 + lib/index.js | 45 - lib/main.js | 256 - manifest.json | 38 - package.json | 58 +- src/main.c | 118 - stats_browser.html | 4842 +++++++++++++++++ stats_node.html | 4842 +++++++++++++++++ test/dist/test.js | 33 - test/test.js | 230 - 53 files changed, 9729 insertions(+), 5476 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 branches.md create mode 100644 browser.js create mode 100644 browser.js.map 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/index.d.ts delete mode 100644 docs/types/test.ts delete mode 100644 examples/c/Makefile delete mode 100644 examples/c/example.c delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/broadcast_shapes.h create mode 100644 index.js create mode 100644 index.js.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 manifest.json delete mode 100644 src/main.c create mode 100644 stats_browser.html create mode 100644 stats_node.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 7f004ad..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 a07d970..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 7292af0..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: '0 12 * * 5' - - # 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 +``` -```javascript -var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); +If no recognized module system is present, access bundle contents via the global scope: + +```html + ``` #### broadcastShapes( shapes ) @@ -245,9 +251,14 @@ var sh = broadcastShapes( [ sh1, sh2 ] ); -```javascript -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); +```html + + + + + + + + ```
@@ -288,131 +304,7 @@ for ( i = 0; i < shapes.length; i++ ) { -* * * - -
- -## C APIs - - - -
- -
- - - - - -
- -### Usage - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -``` - -#### stdlib_ndarray_broadcast_shapes( M, \*\*shapes, \*ndims, \*out ) - -Broadcasts array shapes to a single shape. - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -int64_t N1 = 4; -int64_t sh1[] = { 8, 1, 6, 1 }; - -int64_t N2 = 3; -int64_t sh2[] = { 7, 1, 5 }; - -int64_t ndims[] = { N1, N2 }; -int64_t *shapes[] = { sh1, sh2 }; - -int64_t out[] = { 0, 0, 0, 0 }; -int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -if ( status != 0 ) { - // Handle error... -} -``` - -The function accepts the following arguments: - -- **M**: `[in] int64_t` number of shape arrays. -- **shapes**: `[in] int64_t**` array of shape arrays (dimensions). -- **ndims**: `[in] int64_t*` number of dimensions for each respective shape array. -- **out**: `[out] int64_t*` output shape array. - -```c -int8_t stdlib_ndarray_broadcast_shapes( const int64_t M, const int64_t *shapes[], const int64_t ndims[], int64_t *out ); -``` - -If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). - -
- - - - - -
- -### Notes - -- Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. - -
- - - - - -
- -### Examples - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main( void ) { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} -``` - -
- - - -
- 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.js b/benchmark/benchmark.js deleted file mode 100644 index 6426216..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,112 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pkg = require( './../package.json' ).name; -var broadcastShapes = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::two_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ] ], - [ [ 3, 2 ], [ 3, 1 ] ], - [ [ 1, 1 ], [ 2, 2 ] ], - [ [ 1 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::three_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::four_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ], [ 8, 1, 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ], [ 1, 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ], [ 1, 1, 2, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ], [ 1 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ], [ 5, 1, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/c/Makefile b/benchmark/c/Makefile deleted file mode 100644 index 5dc545c..0000000 --- a/benchmark/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := benchmark.out - - -# RULES # - -#/ -# Compiles C source files. -# -# @param {string} SOURCE_FILES - list of C source files -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lpthread -lblas`) -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [C_COMPILER] - C compiler -# @param {string} [CFLAGS] - C compiler flags -# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} SOURCE_FILES - list of C source files -# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {(string|void)} LIBRARIES - list of libraries (e.g., `-lpthread -lblas`) -# @param {(string|void)} LIBPATH - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} CC - C compiler -# @param {string} CFLAGS - C compiler flags -# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled benchmarks. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/benchmark/c/benchmark.c b/benchmark/c/benchmark.c deleted file mode 100644 index 82d2be5..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,149 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "broadcast-shapes" -#define ITERATIONS 1000000 -#define REPEATS 3 - -/** -* Prints the TAP version. -*/ -static void print_version( void ) { - printf( "TAP version 13\n" ); -} - -/** -* Prints the TAP summary. -* -* @param total total number of tests -* @param passing total number of passing tests -*/ -static void print_summary( int total, int passing ) { - printf( "#\n" ); - printf( "1..%d\n", total ); // TAP plan - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); -} - -/** -* Prints benchmarks results. -* -* @param elapsed elapsed time in seconds -*/ -static void print_results( double elapsed ) { - double rate = (double)ITERATIONS / elapsed; - printf( " ---\n" ); - printf( " iterations: %d\n", ITERATIONS ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", rate ); - printf( " ...\n" ); -} - -/** -* Returns a clock time. -* -* @return clock time -*/ -static double tic( void ) { - struct timeval now; - gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; -} - -/** -* Generates a random number on the interval [0,1). -* -* @return random number -*/ -static double rand_double( void ) { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark( void ) { - double elapsed; - int8_t status; - double t; - int i; - - const int64_t sh1[] = { 8, 1, 6, 1 }; - const int64_t sh2[] = { 7, 1, 5 }; - - const int64_t ndims[] = { 4, 3 }; - const int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( out[ 0 ] != 8 ) { - printf( "unexpected result\n" ); - } - if ( out[ 1 ] != 7 ) { - printf( "unexpected result\n" ); - } - if ( out[ 2 ] != 6 ) { - printf( "unexpected result\n" ); - } - if ( out[ 3 ] != 5 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Main execution sequence. -*/ -int main( void ) { - double elapsed; - int i; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - for ( i = 0; i < REPEATS; i++ ) { - printf( "# c::native::%s::two_arrays\n", NAME ); - elapsed = benchmark(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", i+1 ); - } - print_summary( REPEATS, REPEATS ); -} diff --git a/branches.md b/branches.md deleted file mode 100644 index 79909c9..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes" -%% click B href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/blob/esm/README.md \ No newline at end of file diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..44a8074 --- /dev/null +++ b/browser.js @@ -0,0 +1,3 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map new file mode 100644 index 0000000..aa4b2bb --- /dev/null +++ b/browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"browser.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 87ea8b6..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import broadcastShapes from '../docs/types/index'; -export = broadcastShapes; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 625741a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var d=function(t,e){return function(){return e||t((e={exports:{}}).exports,e),e.exports}};var h=d(function(x,c){ -function g(t){var e,n,u,o,s,l,a,f,i,r,v;if(f=t.length,n=[],f===0)return n;if(o=t[0],i=o.length,f===1){for(r=0;ri&&(i=e[r]);for(r=0;r=0;){for(s=e[0]-i+r,s>=0?u=o[s]:u=1,v=1;v=0?a=t[v][l]:a=1,u===1){u=a;continue}if(!(a===1||u===a))return null}n[r]=u,r-=1}return n}c.exports=g -});var m=h();module.exports=m; -/** @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 db2949f..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = broadcastShapes;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast array shapes to a single shape.\n*\n* @module @stdlib/ndarray-base-broadcast-shapes\n*\n* @example\n* var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' );\n*\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\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,cAkLA,SAASC,EAAiBC,EAAS,CAClC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GAFAH,EAAIR,EAAO,OACXE,EAAM,CAAC,EACFM,IAAM,EACV,OAAON,EAMR,GAJAE,EAAKJ,EAAQ,CAAE,EACfS,EAAIL,EAAG,OAGFI,IAAM,EAAI,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAI,KAAME,EAAIM,CAAE,CAAE,EAEnB,OAAOR,CACR,CAGA,IADAD,EAAQ,CAAEQ,CAAE,EACNC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAM,KAAMD,EAAQU,CAAE,EAAE,MAAO,EAC1BT,EAAOS,CAAE,EAAID,IACjBA,EAAIR,EAAOS,CAAE,GAIf,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAI,KAAM,CAAE,EAIb,IADAQ,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IANAL,EAAKJ,EAAO,CAAE,EAAIQ,EAAIC,EACjBL,GAAM,EACVF,EAAMC,EAAIC,CAAG,EAEbF,EAAM,EAEDQ,EAAI,EAAGA,EAAIH,EAAGG,IAAM,CAOzB,GANAL,EAAKL,EAAOU,CAAE,EAAIF,EAAIC,EACjBJ,GAAM,EACVC,EAAIP,EAAQW,CAAE,EAAGL,CAAG,EAEpBC,EAAI,EAEAJ,IAAQ,EAAI,CAChBA,EAAMI,EACN,QACD,CACA,GAAK,EAAAA,IAAM,GAAKJ,IAAQI,GAKxB,OAAO,IACR,CACAL,EAAKQ,CAAE,EAAIP,EACXO,GAAK,CACN,CACA,OAAOR,CACR,CAKAJ,EAAO,QAAUC,ICxNjB,IAAIa,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "broadcastShapes", "shapes", "ndims", "out", "dim", "sh", "n1", "n2", "d", "M", "N", "i", "j", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f1d92f6..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,39 +0,0 @@ - -{{alias}}( shapes ) - Broadcasts array shapes to a single shape. - - Two respective dimensions in two shape arrays are compatible if - - 1. the dimensions are equal. - 2. one dimension is `1`. - - The function returns `null` if provided incompatible shapes (i.e., shapes - which cannot be broadcast with one another). - - Parameters - ---------- - shapes: Array - Array of shape arrays. - - Returns - ------- - out: Array|null - Broadcast shape. - - Examples - -------- - // Compatible shapes: - > var sh1 = [ 8, 1, 6, 1 ]; - > var sh2 = [ 7, 1, 5 ]; - > var sh = {{alias}}( [ sh1, sh2 ] ) - [ 8, 7, 6, 5 ] - - // Incompatible shapes: - > sh1 = [ 3, 2 ]; - > sh1 = [ 2, 3 ]; - > sh = {{alias}}( [ sh1, sh2 ] ) - null - - See Also - -------- - diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts deleted file mode 100644 index c2702cf..0000000 --- a/docs/types/index.d.ts +++ /dev/null @@ -1,177 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ArrayLike } from '@stdlib/types/array'; - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param shapes - array shapes -* @returns broadcast shape -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -declare function broadcastShapes( shapes: ArrayLike> ): ArrayLike; - - -// EXPORTS // - -export = broadcastShapes; diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 2886539..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 broadcastShapes = require( './index' ); - - -// TESTS // - -// The function returns an array of numbers... -{ - broadcastShapes( [ [ 1, 2 ], [ 2, 2 ] ] ); // $ExpectType ArrayLike -} - -// The compiler throws an error if the function is not provided an array-like object containing array-like objects containing numbers... -{ - broadcastShapes( '5' ); // $ExpectError - broadcastShapes( 5 ); // $ExpectError - broadcastShapes( true ); // $ExpectError - broadcastShapes( false ); // $ExpectError - broadcastShapes( null ); // $ExpectError - broadcastShapes( {} ); // $ExpectError - broadcastShapes( [ '5' ] ); // $ExpectError - broadcastShapes( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - broadcastShapes(); // $ExpectError - broadcastShapes( [ [ 1, 2, 3 ] ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/c/Makefile b/examples/c/Makefile deleted file mode 100644 index 70c91f4..0000000 --- a/examples/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := example.out - - -# RULES # - -#/ -# Compiles source files. -# -# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) -# @param {string} [CFLAGS] - C compiler options -# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) -# @param {string} [SOURCE_FILES] - list of source files -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} CC - C compiler (e.g., `gcc`) -# @param {string} CFLAGS - C compiler options -# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) -# @param {string} SOURCE_FILES - list of source files -# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) -# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled examples. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/examples/c/example.c b/examples/c/example.c deleted file mode 100644 index 4bc54d5..0000000 --- a/examples/c/example.c +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main( void ) { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 28811f9..0000000 --- a/examples/index.js +++ /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. -*/ - -'use strict'; - -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( './../lib' ); - -var shapes; -var out; -var sh; -var i; -var j; - -function shape2string( shape ) { - return lpad( shape.join( ' x ' ), 20, ' ' ); -} - -shapes = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] -]; - -for ( i = 0; i < shapes.length; i++ ) { - sh = shapes[ i ]; - for ( j = 0; j < sh.length; j++ ) { - console.log( shape2string( sh[ j ] ) ); - } - console.log( lpad( '', 20, '-' ) ); - - out = broadcastShapes( sh ); - console.log( shape2string( out )+'\n' ); -} diff --git a/include/stdlib/ndarray/base/broadcast_shapes.h b/include/stdlib/ndarray/base/broadcast_shapes.h deleted file mode 100644 index 33581cb..0000000 --- a/include/stdlib/ndarray/base/broadcast_shapes.h +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#ifndef STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H -#define STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H - -#include - -/* -* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. -*/ -#ifdef __cplusplus -extern "C" { -#endif - -/** -* Broadcasts array shapes to a single shape. -*/ -int8_t stdlib_ndarray_broadcast_shapes( const int64_t M, const int64_t *shapes[], const int64_t ndims[], int64_t *out ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H diff --git a/index.js b/index.js new file mode 100644 index 0000000..d225eb4 --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map new file mode 100644 index 0000000..0c02c0f --- /dev/null +++ b/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 0c9817e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Broadcast array shapes to a single shape. -* -* @module @stdlib/ndarray-base-broadcast-shapes -* -* @example -* var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); -* -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -*/ - -// 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 8558e60..0000000 --- a/lib/main.js +++ /dev/null @@ -1,256 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param {Array} shapes - array of shape arrays -* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`) -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [ 8, 0, 1, 6, 1 ], -* [ 8, 8, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -function broadcastShapes( shapes ) { - var ndims; - var out; - var dim; - var sh; - var n1; - var n2; - var d; - var M; - var N; - var i; - var j; - - M = shapes.length; - out = []; - if ( M === 0 ) { - return out; - } - sh = shapes[ 0 ]; - N = sh.length; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M === 1 ) { - // Need to manually copy to output shape, as shapes could be array-like objects... - for ( i = 0; i < N; i++ ) { - out.push( sh[ i ] ); - } - return out; - } - // Determine the maximum dimensionality... - ndims = [ N ]; - for ( i = 1; i < M; i++ ) { - ndims.push( shapes[ i ].length ); - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Initialize the output array... - for ( i = 0; i < N; i++ ) { - out.push( 0 ); - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim === 1 ) { - dim = d; - continue; - } - if ( d === 1 || dim === d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return null; - } - out[ i ] = dim; - i -= 1; - } - return out; -} - - -// EXPORTS // - -module.exports = broadcastShapes; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 890a937..0000000 --- a/manifest.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "options": {}, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [] - } - ] -} diff --git a/package.json b/package.json index dcdfdb6..a9ff889 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,7 @@ "version": "0.2.2", "description": "Broadcast array shapes to a single shape.", "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", - "include": "./include", - "lib": "./lib", - "src": "./src", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "main": "./index.js", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,33 +12,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/types": "^0.4.3", - "@stdlib/utils-library-manifest": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/string-left-pad": "^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", "stdtypes", @@ -80,9 +27,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 547d921..0000000 --- a/src/main.c +++ /dev/null @@ -1,118 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). -* -* - Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. -* -* @param M number of array shapes -* @param shapes pointer to an array containing shape arrays -* @param ndims array containing the number of dimensions for (i.e., length of) each respective shape array -* @param out pointer to output array -* @return status -* -* @example -* #include "stdlib/ndarray/base/broadcast_shapes.h" -* #include -* -* int64_t N1 = 4; -* int64_t sh1[] = { 8, 1, 6, 1 }; -* -* int64_t N2 = 3; -* int64_t sh2[] = { 7, 1, 5 }; -* -* int64_t ndims[] = { N1, N2 }; -* int64_t *shapes[] = { sh1, sh2 }; -* -* int64_t out[] = { 0, 0, 0, 0 }; -* int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -*/ -int8_t stdlib_ndarray_broadcast_shapes( const int64_t M, const int64_t *shapes[], const int64_t ndims[], int64_t *out ) { - int64_t dim; - const int64_t *sh; - int64_t n1; - int64_t n2; - int64_t d; - int64_t N; - int64_t i; - int64_t j; - - if ( M == 0 ) { - return 0; - } - sh = shapes[ 0 ]; - N = ndims[ 0 ]; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M == 1 ) { - for ( i = 0; i < N; i++ ) { - out[ i ] = sh[ i ]; - } - return 0; - } - // Determine the maximum dimensionality... - for ( i = 1; i < M; i++ ) { - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim == 1 ) { - dim = d; - continue; - } - if ( d == 1 || dim == d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return -1; - } - out[ i ] = dim; - i -= 1; - } - return 0; -} diff --git a/stats_browser.html b/stats_browser.html new file mode 100644 index 0000000..2f35700 --- /dev/null +++ b/stats_browser.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/stats_node.html b/stats_node.html new file mode 100644 index 0000000..c264c7d --- /dev/null +++ b/stats_node.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 63f703c..0000000 --- a/test/test.js +++ /dev/null @@ -1,230 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var broadcastShapes = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastShapes, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] - ]; - - expected = [ - [ 1, 2 ], - [ 3, 4 ], - [ 5, 6, 7 ], - [ 3, 3 ], - [ 3 ], - [ 3, 2 ], - [ 2, 3 ], - [ 1, 2 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty dims)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 0 ], [ 0, 0 ] ], - [ [ 0, 1 ], [ 0, 0 ] ], - [ [ 1, 0 ], [ 0, 1 ] ], - [ [ 1, 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 1, 0 ] ], - [ [ 1, 1 ], [ 0, 1 ] ], - [ [ 0 ], [ 0, 0 ] ], - [ [ 0 ], [ 0, 1 ] ], - [ [ 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 0 ] ], - [ [ 1 ], [ 0, 1 ] ], - [ [ 1 ], [ 1, 0 ] ], - [ [ 1 ], [ 8, 0 ] ], - [ [ 8, 1, 6, 1 ], [ 0, 1, 5 ] ], - [ [ 8, 0, 6, 1 ], [ 1, 5 ] ] - ]; - - expected = [ - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 1, 0 ], - [ 8, 0 ], - [ 8, 0, 6, 5 ], - [ 8, 0, 6, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (no shapes)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [] - ]; - - expected = [ - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty shapes (i.e., zero-dimensional array broadcasting))', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [] ], - [ [], [] ], - [ [], [], [] ], - [ [], [ 0 ] ], - [ [ 0 ], [] ], - [ [], [ 0, 0 ] ], - [ [ 0, 0 ], [] ], - [ [], [ 1, 0 ] ], - [ [], [ 0, 1 ] ], - [ [], [ 3, 3 ] ], - [ [], [ 3, 3 ], [] ] - ]; - - expected = [ - [], - [], - [], - [ 0 ], - [ 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 3, 3 ], - [ 3, 3 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (single shape)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 7 ] ], - [ [ 1, 1 ] ], - [ [ 5, 6, 1 ] ] - ]; - - expected = [ - [ 7 ], - [ 1, 1 ], - [ 5, 6, 1 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function returns `null` if provided incompatible shapes', function test( t ) { - var actual; - var values; - var i; - - values = [ - [ [ 3 ], [ 4 ] ], - [ [ 2, 3 ], [ 2 ] ], - [ [ 3 ], [ 3 ], [ 4 ] ], - [ [ 1, 3, 4 ], [ 2, 3, 3 ] ], - [ [ 1, 2 ], [ 3, 1 ], [ 3, 2 ], [ 10, 5 ] ], - [ [ 2 ], [ 2, 3 ] ], - [ [ 2 ], [ 2 ], [ 2 ], [ 2 ], [ 3 ], [ 3 ], [ 3 ], [ 3 ] ], - [ [ 9, 0, 9 ], [ 0, 9, 0 ] ], - [ [ 9, 9, 9 ], [ 0, 9, 9 ] ], - [ [ 9, 0, 9 ], [ 9, 9, 9 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 0 ] ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.strictEqual( actual, null, 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); From 0cad58580a0bca63ba6b7032190a83962ced001a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 30 Dec 2024 01:31:29 +0000 Subject: [PATCH 138/158] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 6259d77..dcdfdb6 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,8 @@ }, "dependencies": { "@stdlib/types": "^0.4.3", - "@stdlib/utils-library-manifest": "^0.2.2" + "@stdlib/utils-library-manifest": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, "devDependencies": { "@stdlib/string-left-pad": "^0.2.2", @@ -84,4 +85,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From 5265e1b8d727cd40de171d2bd96687631fbfd1e4 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 30 Dec 2024 01:33:00 +0000 Subject: [PATCH 139/158] Remove files --- browser.js | 3 - browser.js.map | 1 - index.js | 3 - index.js.map | 1 - stats_browser.html | 4842 -------------------------------------------- stats_node.html | 4842 -------------------------------------------- 6 files changed, 9692 deletions(-) delete mode 100644 browser.js delete mode 100644 browser.js.map delete mode 100644 index.js delete mode 100644 index.js.map delete mode 100644 stats_browser.html delete mode 100644 stats_node.html diff --git a/browser.js b/browser.js deleted file mode 100644 index 44a8074..0000000 --- a/browser.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); -//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map deleted file mode 100644 index aa4b2bb..0000000 --- a/browser.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"browser.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/index.js b/index.js deleted file mode 100644 index d225eb4..0000000 --- a/index.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); -//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map deleted file mode 100644 index 0c02c0f..0000000 --- a/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/stats_browser.html b/stats_browser.html deleted file mode 100644 index 2f35700..0000000 --- a/stats_browser.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - diff --git a/stats_node.html b/stats_node.html deleted file mode 100644 index c264c7d..0000000 --- a/stats_node.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From ef58d37b90ba6d109c2049362e0295e410c24ab5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 30 Dec 2024 01:33:14 +0000 Subject: [PATCH 140/158] 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 | 243 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 178 +- SECURITY.md | 5 - benchmark/benchmark.js | 112 - benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 149 - branches.md | 56 - browser.js | 3 + browser.js.map | 1 + dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 39 - docs/types/index.d.ts | 177 - docs/types/test.ts | 45 - examples/c/Makefile | 146 - examples/c/example.c | 50 - examples/index.js | 54 - .../stdlib/ndarray/base/broadcast_shapes.h | 40 - index.js | 3 + index.js.map | 1 + lib/index.js | 45 - lib/main.js | 256 - manifest.json | 38 - package.json | 58 +- src/main.c | 118 - stats_browser.html | 4842 +++++++++++++++++ stats_node.html | 4842 +++++++++++++++++ test/dist/test.js | 33 - test/test.js | 230 - 54 files changed, 9729 insertions(+), 5477 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.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 branches.md create mode 100644 browser.js create mode 100644 browser.js.map 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/index.d.ts delete mode 100644 docs/types/test.ts delete mode 100644 examples/c/Makefile delete mode 100644 examples/c/example.c delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/broadcast_shapes.h create mode 100644 index.js create mode 100644 index.js.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 manifest.json delete mode 100644 src/main.c create mode 100644 stats_browser.html create mode 100644 stats_node.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 118fe7e..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-12-30T01:30:56.133Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 7f004ad..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 a07d970..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 7292af0..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: '0 12 * * 5' - - # 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 +``` -```javascript -var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); +If no recognized module system is present, access bundle contents via the global scope: + +```html + ``` #### broadcastShapes( shapes ) @@ -245,9 +251,14 @@ var sh = broadcastShapes( [ sh1, sh2 ] ); -```javascript -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); +```html + + + + + + + + ```
@@ -288,131 +304,7 @@ for ( i = 0; i < shapes.length; i++ ) { -* * * - -
- -## C APIs - - - -
- -
- - - - - -
- -### Usage - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -``` - -#### stdlib_ndarray_broadcast_shapes( M, \*\*shapes, \*ndims, \*out ) - -Broadcasts array shapes to a single shape. - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -int64_t N1 = 4; -int64_t sh1[] = { 8, 1, 6, 1 }; - -int64_t N2 = 3; -int64_t sh2[] = { 7, 1, 5 }; - -int64_t ndims[] = { N1, N2 }; -int64_t *shapes[] = { sh1, sh2 }; - -int64_t out[] = { 0, 0, 0, 0 }; -int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -if ( status != 0 ) { - // Handle error... -} -``` - -The function accepts the following arguments: - -- **M**: `[in] int64_t` number of shape arrays. -- **shapes**: `[in] int64_t**` array of shape arrays (dimensions). -- **ndims**: `[in] int64_t*` number of dimensions for each respective shape array. -- **out**: `[out] int64_t*` output shape array. - -```c -int8_t stdlib_ndarray_broadcast_shapes( const int64_t M, const int64_t *shapes[], const int64_t ndims[], int64_t *out ); -``` - -If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). - -
- - - - - -
- -### Notes - -- Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. - -
- - - - - -
- -### Examples - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main( void ) { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} -``` - -
- - - -
- 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.js b/benchmark/benchmark.js deleted file mode 100644 index 6426216..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,112 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pkg = require( './../package.json' ).name; -var broadcastShapes = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::two_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ] ], - [ [ 3, 2 ], [ 3, 1 ] ], - [ [ 1, 1 ], [ 2, 2 ] ], - [ [ 1 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::three_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::four_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ], [ 8, 1, 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ], [ 1, 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ], [ 1, 1, 2, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ], [ 1 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ], [ 5, 1, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/c/Makefile b/benchmark/c/Makefile deleted file mode 100644 index 5dc545c..0000000 --- a/benchmark/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := benchmark.out - - -# RULES # - -#/ -# Compiles C source files. -# -# @param {string} SOURCE_FILES - list of C source files -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lpthread -lblas`) -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [C_COMPILER] - C compiler -# @param {string} [CFLAGS] - C compiler flags -# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} SOURCE_FILES - list of C source files -# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {(string|void)} LIBRARIES - list of libraries (e.g., `-lpthread -lblas`) -# @param {(string|void)} LIBPATH - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} CC - C compiler -# @param {string} CFLAGS - C compiler flags -# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled benchmarks. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/benchmark/c/benchmark.c b/benchmark/c/benchmark.c deleted file mode 100644 index 82d2be5..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,149 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "broadcast-shapes" -#define ITERATIONS 1000000 -#define REPEATS 3 - -/** -* Prints the TAP version. -*/ -static void print_version( void ) { - printf( "TAP version 13\n" ); -} - -/** -* Prints the TAP summary. -* -* @param total total number of tests -* @param passing total number of passing tests -*/ -static void print_summary( int total, int passing ) { - printf( "#\n" ); - printf( "1..%d\n", total ); // TAP plan - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); -} - -/** -* Prints benchmarks results. -* -* @param elapsed elapsed time in seconds -*/ -static void print_results( double elapsed ) { - double rate = (double)ITERATIONS / elapsed; - printf( " ---\n" ); - printf( " iterations: %d\n", ITERATIONS ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", rate ); - printf( " ...\n" ); -} - -/** -* Returns a clock time. -* -* @return clock time -*/ -static double tic( void ) { - struct timeval now; - gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; -} - -/** -* Generates a random number on the interval [0,1). -* -* @return random number -*/ -static double rand_double( void ) { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark( void ) { - double elapsed; - int8_t status; - double t; - int i; - - const int64_t sh1[] = { 8, 1, 6, 1 }; - const int64_t sh2[] = { 7, 1, 5 }; - - const int64_t ndims[] = { 4, 3 }; - const int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( out[ 0 ] != 8 ) { - printf( "unexpected result\n" ); - } - if ( out[ 1 ] != 7 ) { - printf( "unexpected result\n" ); - } - if ( out[ 2 ] != 6 ) { - printf( "unexpected result\n" ); - } - if ( out[ 3 ] != 5 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Main execution sequence. -*/ -int main( void ) { - double elapsed; - int i; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - for ( i = 0; i < REPEATS; i++ ) { - printf( "# c::native::%s::two_arrays\n", NAME ); - elapsed = benchmark(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", i+1 ); - } - print_summary( REPEATS, REPEATS ); -} diff --git a/branches.md b/branches.md deleted file mode 100644 index 79909c9..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes" -%% click B href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/blob/esm/README.md \ No newline at end of file diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..44a8074 --- /dev/null +++ b/browser.js @@ -0,0 +1,3 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map new file mode 100644 index 0000000..aa4b2bb --- /dev/null +++ b/browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"browser.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 87ea8b6..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import broadcastShapes from '../docs/types/index'; -export = broadcastShapes; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 625741a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var d=function(t,e){return function(){return e||t((e={exports:{}}).exports,e),e.exports}};var h=d(function(x,c){ -function g(t){var e,n,u,o,s,l,a,f,i,r,v;if(f=t.length,n=[],f===0)return n;if(o=t[0],i=o.length,f===1){for(r=0;ri&&(i=e[r]);for(r=0;r=0;){for(s=e[0]-i+r,s>=0?u=o[s]:u=1,v=1;v=0?a=t[v][l]:a=1,u===1){u=a;continue}if(!(a===1||u===a))return null}n[r]=u,r-=1}return n}c.exports=g -});var m=h();module.exports=m; -/** @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 db2949f..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = broadcastShapes;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast array shapes to a single shape.\n*\n* @module @stdlib/ndarray-base-broadcast-shapes\n*\n* @example\n* var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' );\n*\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\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,cAkLA,SAASC,EAAiBC,EAAS,CAClC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GAFAH,EAAIR,EAAO,OACXE,EAAM,CAAC,EACFM,IAAM,EACV,OAAON,EAMR,GAJAE,EAAKJ,EAAQ,CAAE,EACfS,EAAIL,EAAG,OAGFI,IAAM,EAAI,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAI,KAAME,EAAIM,CAAE,CAAE,EAEnB,OAAOR,CACR,CAGA,IADAD,EAAQ,CAAEQ,CAAE,EACNC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAM,KAAMD,EAAQU,CAAE,EAAE,MAAO,EAC1BT,EAAOS,CAAE,EAAID,IACjBA,EAAIR,EAAOS,CAAE,GAIf,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAI,KAAM,CAAE,EAIb,IADAQ,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IANAL,EAAKJ,EAAO,CAAE,EAAIQ,EAAIC,EACjBL,GAAM,EACVF,EAAMC,EAAIC,CAAG,EAEbF,EAAM,EAEDQ,EAAI,EAAGA,EAAIH,EAAGG,IAAM,CAOzB,GANAL,EAAKL,EAAOU,CAAE,EAAIF,EAAIC,EACjBJ,GAAM,EACVC,EAAIP,EAAQW,CAAE,EAAGL,CAAG,EAEpBC,EAAI,EAEAJ,IAAQ,EAAI,CAChBA,EAAMI,EACN,QACD,CACA,GAAK,EAAAA,IAAM,GAAKJ,IAAQI,GAKxB,OAAO,IACR,CACAL,EAAKQ,CAAE,EAAIP,EACXO,GAAK,CACN,CACA,OAAOR,CACR,CAKAJ,EAAO,QAAUC,ICxNjB,IAAIa,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "broadcastShapes", "shapes", "ndims", "out", "dim", "sh", "n1", "n2", "d", "M", "N", "i", "j", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f1d92f6..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,39 +0,0 @@ - -{{alias}}( shapes ) - Broadcasts array shapes to a single shape. - - Two respective dimensions in two shape arrays are compatible if - - 1. the dimensions are equal. - 2. one dimension is `1`. - - The function returns `null` if provided incompatible shapes (i.e., shapes - which cannot be broadcast with one another). - - Parameters - ---------- - shapes: Array - Array of shape arrays. - - Returns - ------- - out: Array|null - Broadcast shape. - - Examples - -------- - // Compatible shapes: - > var sh1 = [ 8, 1, 6, 1 ]; - > var sh2 = [ 7, 1, 5 ]; - > var sh = {{alias}}( [ sh1, sh2 ] ) - [ 8, 7, 6, 5 ] - - // Incompatible shapes: - > sh1 = [ 3, 2 ]; - > sh1 = [ 2, 3 ]; - > sh = {{alias}}( [ sh1, sh2 ] ) - null - - See Also - -------- - diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts deleted file mode 100644 index c2702cf..0000000 --- a/docs/types/index.d.ts +++ /dev/null @@ -1,177 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ArrayLike } from '@stdlib/types/array'; - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param shapes - array shapes -* @returns broadcast shape -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -declare function broadcastShapes( shapes: ArrayLike> ): ArrayLike; - - -// EXPORTS // - -export = broadcastShapes; diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 2886539..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 broadcastShapes = require( './index' ); - - -// TESTS // - -// The function returns an array of numbers... -{ - broadcastShapes( [ [ 1, 2 ], [ 2, 2 ] ] ); // $ExpectType ArrayLike -} - -// The compiler throws an error if the function is not provided an array-like object containing array-like objects containing numbers... -{ - broadcastShapes( '5' ); // $ExpectError - broadcastShapes( 5 ); // $ExpectError - broadcastShapes( true ); // $ExpectError - broadcastShapes( false ); // $ExpectError - broadcastShapes( null ); // $ExpectError - broadcastShapes( {} ); // $ExpectError - broadcastShapes( [ '5' ] ); // $ExpectError - broadcastShapes( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - broadcastShapes(); // $ExpectError - broadcastShapes( [ [ 1, 2, 3 ] ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/c/Makefile b/examples/c/Makefile deleted file mode 100644 index 70c91f4..0000000 --- a/examples/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := example.out - - -# RULES # - -#/ -# Compiles source files. -# -# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) -# @param {string} [CFLAGS] - C compiler options -# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) -# @param {string} [SOURCE_FILES] - list of source files -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} CC - C compiler (e.g., `gcc`) -# @param {string} CFLAGS - C compiler options -# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) -# @param {string} SOURCE_FILES - list of source files -# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) -# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled examples. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/examples/c/example.c b/examples/c/example.c deleted file mode 100644 index 4bc54d5..0000000 --- a/examples/c/example.c +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main( void ) { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 28811f9..0000000 --- a/examples/index.js +++ /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. -*/ - -'use strict'; - -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( './../lib' ); - -var shapes; -var out; -var sh; -var i; -var j; - -function shape2string( shape ) { - return lpad( shape.join( ' x ' ), 20, ' ' ); -} - -shapes = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] -]; - -for ( i = 0; i < shapes.length; i++ ) { - sh = shapes[ i ]; - for ( j = 0; j < sh.length; j++ ) { - console.log( shape2string( sh[ j ] ) ); - } - console.log( lpad( '', 20, '-' ) ); - - out = broadcastShapes( sh ); - console.log( shape2string( out )+'\n' ); -} diff --git a/include/stdlib/ndarray/base/broadcast_shapes.h b/include/stdlib/ndarray/base/broadcast_shapes.h deleted file mode 100644 index 33581cb..0000000 --- a/include/stdlib/ndarray/base/broadcast_shapes.h +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#ifndef STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H -#define STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H - -#include - -/* -* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. -*/ -#ifdef __cplusplus -extern "C" { -#endif - -/** -* Broadcasts array shapes to a single shape. -*/ -int8_t stdlib_ndarray_broadcast_shapes( const int64_t M, const int64_t *shapes[], const int64_t ndims[], int64_t *out ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H diff --git a/index.js b/index.js new file mode 100644 index 0000000..d225eb4 --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map new file mode 100644 index 0000000..0c02c0f --- /dev/null +++ b/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 0c9817e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Broadcast array shapes to a single shape. -* -* @module @stdlib/ndarray-base-broadcast-shapes -* -* @example -* var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); -* -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -*/ - -// 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 8558e60..0000000 --- a/lib/main.js +++ /dev/null @@ -1,256 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param {Array} shapes - array of shape arrays -* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`) -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [ 8, 0, 1, 6, 1 ], -* [ 8, 8, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -function broadcastShapes( shapes ) { - var ndims; - var out; - var dim; - var sh; - var n1; - var n2; - var d; - var M; - var N; - var i; - var j; - - M = shapes.length; - out = []; - if ( M === 0 ) { - return out; - } - sh = shapes[ 0 ]; - N = sh.length; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M === 1 ) { - // Need to manually copy to output shape, as shapes could be array-like objects... - for ( i = 0; i < N; i++ ) { - out.push( sh[ i ] ); - } - return out; - } - // Determine the maximum dimensionality... - ndims = [ N ]; - for ( i = 1; i < M; i++ ) { - ndims.push( shapes[ i ].length ); - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Initialize the output array... - for ( i = 0; i < N; i++ ) { - out.push( 0 ); - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim === 1 ) { - dim = d; - continue; - } - if ( d === 1 || dim === d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return null; - } - out[ i ] = dim; - i -= 1; - } - return out; -} - - -// EXPORTS // - -module.exports = broadcastShapes; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 890a937..0000000 --- a/manifest.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "options": {}, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [] - } - ] -} diff --git a/package.json b/package.json index dcdfdb6..a9ff889 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,7 @@ "version": "0.2.2", "description": "Broadcast array shapes to a single shape.", "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", - "include": "./include", - "lib": "./lib", - "src": "./src", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "main": "./index.js", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,33 +12,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/types": "^0.4.3", - "@stdlib/utils-library-manifest": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/string-left-pad": "^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", "stdtypes", @@ -80,9 +27,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 547d921..0000000 --- a/src/main.c +++ /dev/null @@ -1,118 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). -* -* - Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. -* -* @param M number of array shapes -* @param shapes pointer to an array containing shape arrays -* @param ndims array containing the number of dimensions for (i.e., length of) each respective shape array -* @param out pointer to output array -* @return status -* -* @example -* #include "stdlib/ndarray/base/broadcast_shapes.h" -* #include -* -* int64_t N1 = 4; -* int64_t sh1[] = { 8, 1, 6, 1 }; -* -* int64_t N2 = 3; -* int64_t sh2[] = { 7, 1, 5 }; -* -* int64_t ndims[] = { N1, N2 }; -* int64_t *shapes[] = { sh1, sh2 }; -* -* int64_t out[] = { 0, 0, 0, 0 }; -* int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -*/ -int8_t stdlib_ndarray_broadcast_shapes( const int64_t M, const int64_t *shapes[], const int64_t ndims[], int64_t *out ) { - int64_t dim; - const int64_t *sh; - int64_t n1; - int64_t n2; - int64_t d; - int64_t N; - int64_t i; - int64_t j; - - if ( M == 0 ) { - return 0; - } - sh = shapes[ 0 ]; - N = ndims[ 0 ]; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M == 1 ) { - for ( i = 0; i < N; i++ ) { - out[ i ] = sh[ i ]; - } - return 0; - } - // Determine the maximum dimensionality... - for ( i = 1; i < M; i++ ) { - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim == 1 ) { - dim = d; - continue; - } - if ( d == 1 || dim == d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return -1; - } - out[ i ] = dim; - i -= 1; - } - return 0; -} diff --git a/stats_browser.html b/stats_browser.html new file mode 100644 index 0000000..2f35700 --- /dev/null +++ b/stats_browser.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/stats_node.html b/stats_node.html new file mode 100644 index 0000000..c264c7d --- /dev/null +++ b/stats_node.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 63f703c..0000000 --- a/test/test.js +++ /dev/null @@ -1,230 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var broadcastShapes = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastShapes, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] - ]; - - expected = [ - [ 1, 2 ], - [ 3, 4 ], - [ 5, 6, 7 ], - [ 3, 3 ], - [ 3 ], - [ 3, 2 ], - [ 2, 3 ], - [ 1, 2 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty dims)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 0 ], [ 0, 0 ] ], - [ [ 0, 1 ], [ 0, 0 ] ], - [ [ 1, 0 ], [ 0, 1 ] ], - [ [ 1, 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 1, 0 ] ], - [ [ 1, 1 ], [ 0, 1 ] ], - [ [ 0 ], [ 0, 0 ] ], - [ [ 0 ], [ 0, 1 ] ], - [ [ 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 0 ] ], - [ [ 1 ], [ 0, 1 ] ], - [ [ 1 ], [ 1, 0 ] ], - [ [ 1 ], [ 8, 0 ] ], - [ [ 8, 1, 6, 1 ], [ 0, 1, 5 ] ], - [ [ 8, 0, 6, 1 ], [ 1, 5 ] ] - ]; - - expected = [ - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 1, 0 ], - [ 8, 0 ], - [ 8, 0, 6, 5 ], - [ 8, 0, 6, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (no shapes)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [] - ]; - - expected = [ - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty shapes (i.e., zero-dimensional array broadcasting))', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [] ], - [ [], [] ], - [ [], [], [] ], - [ [], [ 0 ] ], - [ [ 0 ], [] ], - [ [], [ 0, 0 ] ], - [ [ 0, 0 ], [] ], - [ [], [ 1, 0 ] ], - [ [], [ 0, 1 ] ], - [ [], [ 3, 3 ] ], - [ [], [ 3, 3 ], [] ] - ]; - - expected = [ - [], - [], - [], - [ 0 ], - [ 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 3, 3 ], - [ 3, 3 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (single shape)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 7 ] ], - [ [ 1, 1 ] ], - [ [ 5, 6, 1 ] ] - ]; - - expected = [ - [ 7 ], - [ 1, 1 ], - [ 5, 6, 1 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function returns `null` if provided incompatible shapes', function test( t ) { - var actual; - var values; - var i; - - values = [ - [ [ 3 ], [ 4 ] ], - [ [ 2, 3 ], [ 2 ] ], - [ [ 3 ], [ 3 ], [ 4 ] ], - [ [ 1, 3, 4 ], [ 2, 3, 3 ] ], - [ [ 1, 2 ], [ 3, 1 ], [ 3, 2 ], [ 10, 5 ] ], - [ [ 2 ], [ 2, 3 ] ], - [ [ 2 ], [ 2 ], [ 2 ], [ 2 ], [ 3 ], [ 3 ], [ 3 ], [ 3 ] ], - [ [ 9, 0, 9 ], [ 0, 9, 0 ] ], - [ [ 9, 9, 9 ], [ 0, 9, 9 ] ], - [ [ 9, 0, 9 ], [ 9, 9, 9 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 0 ] ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.strictEqual( actual, null, 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); From 9c18f4d246a3b7593d35a1964ab530cbced9fcfb Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 13 Jan 2025 01:58:10 +0000 Subject: [PATCH 141/158] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 6259d77..dcdfdb6 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,8 @@ }, "dependencies": { "@stdlib/types": "^0.4.3", - "@stdlib/utils-library-manifest": "^0.2.2" + "@stdlib/utils-library-manifest": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, "devDependencies": { "@stdlib/string-left-pad": "^0.2.2", @@ -84,4 +85,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From ae0c7ff720e41264c274c14bda954dc503129736 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 13 Jan 2025 02:20:36 +0000 Subject: [PATCH 142/158] Remove files --- browser.js | 3 - browser.js.map | 1 - index.js | 3 - index.js.map | 1 - stats_browser.html | 4842 -------------------------------------------- stats_node.html | 4842 -------------------------------------------- 6 files changed, 9692 deletions(-) delete mode 100644 browser.js delete mode 100644 browser.js.map delete mode 100644 index.js delete mode 100644 index.js.map delete mode 100644 stats_browser.html delete mode 100644 stats_node.html diff --git a/browser.js b/browser.js deleted file mode 100644 index 44a8074..0000000 --- a/browser.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); -//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map deleted file mode 100644 index aa4b2bb..0000000 --- a/browser.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"browser.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/index.js b/index.js deleted file mode 100644 index d225eb4..0000000 --- a/index.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); -//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map deleted file mode 100644 index 0c02c0f..0000000 --- a/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/stats_browser.html b/stats_browser.html deleted file mode 100644 index 2f35700..0000000 --- a/stats_browser.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - diff --git a/stats_node.html b/stats_node.html deleted file mode 100644 index c264c7d..0000000 --- a/stats_node.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 96f6f54af46083bbe01c2d36be586507d7e6e1f0 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 13 Jan 2025 02:20:53 +0000 Subject: [PATCH 143/158] 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 | 243 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 178 +- SECURITY.md | 5 - benchmark/benchmark.js | 112 - benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 149 - branches.md | 56 - browser.js | 3 + browser.js.map | 1 + dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 39 - docs/types/index.d.ts | 177 - docs/types/test.ts | 45 - examples/c/Makefile | 146 - examples/c/example.c | 50 - examples/index.js | 54 - .../stdlib/ndarray/base/broadcast_shapes.h | 40 - index.js | 3 + index.js.map | 1 + lib/index.js | 45 - lib/main.js | 256 - manifest.json | 38 - package.json | 58 +- src/main.c | 118 - stats_browser.html | 4842 +++++++++++++++++ stats_node.html | 4842 +++++++++++++++++ test/dist/test.js | 33 - test/test.js | 230 - 54 files changed, 9729 insertions(+), 5477 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.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 branches.md create mode 100644 browser.js create mode 100644 browser.js.map 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/index.d.ts delete mode 100644 docs/types/test.ts delete mode 100644 examples/c/Makefile delete mode 100644 examples/c/example.c delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/broadcast_shapes.h create mode 100644 index.js create mode 100644 index.js.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 manifest.json delete mode 100644 src/main.c create mode 100644 stats_browser.html create mode 100644 stats_node.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 116cf9c..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2025-01-13T01:52:55.779Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 7f004ad..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 a07d970..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 7292af0..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: '0 12 * * 5' - - # 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 +``` -```javascript -var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); +If no recognized module system is present, access bundle contents via the global scope: + +```html + ``` #### broadcastShapes( shapes ) @@ -245,9 +251,14 @@ var sh = broadcastShapes( [ sh1, sh2 ] ); -```javascript -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); +```html + + + + + + + + ```
@@ -288,131 +304,7 @@ for ( i = 0; i < shapes.length; i++ ) { -* * * - -
- -## C APIs - - - -
- -
- - - - - -
- -### Usage - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -``` - -#### stdlib_ndarray_broadcast_shapes( M, \*\*shapes, \*ndims, \*out ) - -Broadcasts array shapes to a single shape. - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -int64_t N1 = 4; -int64_t sh1[] = { 8, 1, 6, 1 }; - -int64_t N2 = 3; -int64_t sh2[] = { 7, 1, 5 }; - -int64_t ndims[] = { N1, N2 }; -int64_t *shapes[] = { sh1, sh2 }; - -int64_t out[] = { 0, 0, 0, 0 }; -int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -if ( status != 0 ) { - // Handle error... -} -``` - -The function accepts the following arguments: - -- **M**: `[in] int64_t` number of shape arrays. -- **shapes**: `[in] int64_t**` array of shape arrays (dimensions). -- **ndims**: `[in] int64_t*` number of dimensions for each respective shape array. -- **out**: `[out] int64_t*` output shape array. - -```c -int8_t stdlib_ndarray_broadcast_shapes( const int64_t M, const int64_t *shapes[], const int64_t ndims[], int64_t *out ); -``` - -If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). - -
- - - - - -
- -### Notes - -- Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. - -
- - - - - -
- -### Examples - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main( void ) { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} -``` - -
- - - -
- 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.js b/benchmark/benchmark.js deleted file mode 100644 index 6426216..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,112 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pkg = require( './../package.json' ).name; -var broadcastShapes = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::two_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ] ], - [ [ 3, 2 ], [ 3, 1 ] ], - [ [ 1, 1 ], [ 2, 2 ] ], - [ [ 1 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::three_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::four_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ], [ 8, 1, 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ], [ 1, 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ], [ 1, 1, 2, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ], [ 1 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ], [ 5, 1, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/c/Makefile b/benchmark/c/Makefile deleted file mode 100644 index 5dc545c..0000000 --- a/benchmark/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := benchmark.out - - -# RULES # - -#/ -# Compiles C source files. -# -# @param {string} SOURCE_FILES - list of C source files -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lpthread -lblas`) -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [C_COMPILER] - C compiler -# @param {string} [CFLAGS] - C compiler flags -# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} SOURCE_FILES - list of C source files -# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {(string|void)} LIBRARIES - list of libraries (e.g., `-lpthread -lblas`) -# @param {(string|void)} LIBPATH - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} CC - C compiler -# @param {string} CFLAGS - C compiler flags -# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled benchmarks. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/benchmark/c/benchmark.c b/benchmark/c/benchmark.c deleted file mode 100644 index 82d2be5..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,149 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "broadcast-shapes" -#define ITERATIONS 1000000 -#define REPEATS 3 - -/** -* Prints the TAP version. -*/ -static void print_version( void ) { - printf( "TAP version 13\n" ); -} - -/** -* Prints the TAP summary. -* -* @param total total number of tests -* @param passing total number of passing tests -*/ -static void print_summary( int total, int passing ) { - printf( "#\n" ); - printf( "1..%d\n", total ); // TAP plan - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); -} - -/** -* Prints benchmarks results. -* -* @param elapsed elapsed time in seconds -*/ -static void print_results( double elapsed ) { - double rate = (double)ITERATIONS / elapsed; - printf( " ---\n" ); - printf( " iterations: %d\n", ITERATIONS ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", rate ); - printf( " ...\n" ); -} - -/** -* Returns a clock time. -* -* @return clock time -*/ -static double tic( void ) { - struct timeval now; - gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; -} - -/** -* Generates a random number on the interval [0,1). -* -* @return random number -*/ -static double rand_double( void ) { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark( void ) { - double elapsed; - int8_t status; - double t; - int i; - - const int64_t sh1[] = { 8, 1, 6, 1 }; - const int64_t sh2[] = { 7, 1, 5 }; - - const int64_t ndims[] = { 4, 3 }; - const int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( out[ 0 ] != 8 ) { - printf( "unexpected result\n" ); - } - if ( out[ 1 ] != 7 ) { - printf( "unexpected result\n" ); - } - if ( out[ 2 ] != 6 ) { - printf( "unexpected result\n" ); - } - if ( out[ 3 ] != 5 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Main execution sequence. -*/ -int main( void ) { - double elapsed; - int i; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - for ( i = 0; i < REPEATS; i++ ) { - printf( "# c::native::%s::two_arrays\n", NAME ); - elapsed = benchmark(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", i+1 ); - } - print_summary( REPEATS, REPEATS ); -} diff --git a/branches.md b/branches.md deleted file mode 100644 index 79909c9..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes" -%% click B href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/blob/esm/README.md \ No newline at end of file diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..14405dc --- /dev/null +++ b/browser.js @@ -0,0 +1,3 @@ +// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map new file mode 100644 index 0000000..aa4b2bb --- /dev/null +++ b/browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"browser.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 87ea8b6..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import broadcastShapes from '../docs/types/index'; -export = broadcastShapes; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 625741a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var d=function(t,e){return function(){return e||t((e={exports:{}}).exports,e),e.exports}};var h=d(function(x,c){ -function g(t){var e,n,u,o,s,l,a,f,i,r,v;if(f=t.length,n=[],f===0)return n;if(o=t[0],i=o.length,f===1){for(r=0;ri&&(i=e[r]);for(r=0;r=0;){for(s=e[0]-i+r,s>=0?u=o[s]:u=1,v=1;v=0?a=t[v][l]:a=1,u===1){u=a;continue}if(!(a===1||u===a))return null}n[r]=u,r-=1}return n}c.exports=g -});var m=h();module.exports=m; -/** @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 db2949f..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = broadcastShapes;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast array shapes to a single shape.\n*\n* @module @stdlib/ndarray-base-broadcast-shapes\n*\n* @example\n* var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' );\n*\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\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,cAkLA,SAASC,EAAiBC,EAAS,CAClC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GAFAH,EAAIR,EAAO,OACXE,EAAM,CAAC,EACFM,IAAM,EACV,OAAON,EAMR,GAJAE,EAAKJ,EAAQ,CAAE,EACfS,EAAIL,EAAG,OAGFI,IAAM,EAAI,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAI,KAAME,EAAIM,CAAE,CAAE,EAEnB,OAAOR,CACR,CAGA,IADAD,EAAQ,CAAEQ,CAAE,EACNC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAM,KAAMD,EAAQU,CAAE,EAAE,MAAO,EAC1BT,EAAOS,CAAE,EAAID,IACjBA,EAAIR,EAAOS,CAAE,GAIf,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAI,KAAM,CAAE,EAIb,IADAQ,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IANAL,EAAKJ,EAAO,CAAE,EAAIQ,EAAIC,EACjBL,GAAM,EACVF,EAAMC,EAAIC,CAAG,EAEbF,EAAM,EAEDQ,EAAI,EAAGA,EAAIH,EAAGG,IAAM,CAOzB,GANAL,EAAKL,EAAOU,CAAE,EAAIF,EAAIC,EACjBJ,GAAM,EACVC,EAAIP,EAAQW,CAAE,EAAGL,CAAG,EAEpBC,EAAI,EAEAJ,IAAQ,EAAI,CAChBA,EAAMI,EACN,QACD,CACA,GAAK,EAAAA,IAAM,GAAKJ,IAAQI,GAKxB,OAAO,IACR,CACAL,EAAKQ,CAAE,EAAIP,EACXO,GAAK,CACN,CACA,OAAOR,CACR,CAKAJ,EAAO,QAAUC,ICxNjB,IAAIa,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "broadcastShapes", "shapes", "ndims", "out", "dim", "sh", "n1", "n2", "d", "M", "N", "i", "j", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f1d92f6..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,39 +0,0 @@ - -{{alias}}( shapes ) - Broadcasts array shapes to a single shape. - - Two respective dimensions in two shape arrays are compatible if - - 1. the dimensions are equal. - 2. one dimension is `1`. - - The function returns `null` if provided incompatible shapes (i.e., shapes - which cannot be broadcast with one another). - - Parameters - ---------- - shapes: Array - Array of shape arrays. - - Returns - ------- - out: Array|null - Broadcast shape. - - Examples - -------- - // Compatible shapes: - > var sh1 = [ 8, 1, 6, 1 ]; - > var sh2 = [ 7, 1, 5 ]; - > var sh = {{alias}}( [ sh1, sh2 ] ) - [ 8, 7, 6, 5 ] - - // Incompatible shapes: - > sh1 = [ 3, 2 ]; - > sh1 = [ 2, 3 ]; - > sh = {{alias}}( [ sh1, sh2 ] ) - null - - See Also - -------- - diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts deleted file mode 100644 index c2702cf..0000000 --- a/docs/types/index.d.ts +++ /dev/null @@ -1,177 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ArrayLike } from '@stdlib/types/array'; - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param shapes - array shapes -* @returns broadcast shape -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -declare function broadcastShapes( shapes: ArrayLike> ): ArrayLike; - - -// EXPORTS // - -export = broadcastShapes; diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 2886539..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 broadcastShapes = require( './index' ); - - -// TESTS // - -// The function returns an array of numbers... -{ - broadcastShapes( [ [ 1, 2 ], [ 2, 2 ] ] ); // $ExpectType ArrayLike -} - -// The compiler throws an error if the function is not provided an array-like object containing array-like objects containing numbers... -{ - broadcastShapes( '5' ); // $ExpectError - broadcastShapes( 5 ); // $ExpectError - broadcastShapes( true ); // $ExpectError - broadcastShapes( false ); // $ExpectError - broadcastShapes( null ); // $ExpectError - broadcastShapes( {} ); // $ExpectError - broadcastShapes( [ '5' ] ); // $ExpectError - broadcastShapes( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - broadcastShapes(); // $ExpectError - broadcastShapes( [ [ 1, 2, 3 ] ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/c/Makefile b/examples/c/Makefile deleted file mode 100644 index 70c91f4..0000000 --- a/examples/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := example.out - - -# RULES # - -#/ -# Compiles source files. -# -# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) -# @param {string} [CFLAGS] - C compiler options -# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) -# @param {string} [SOURCE_FILES] - list of source files -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} CC - C compiler (e.g., `gcc`) -# @param {string} CFLAGS - C compiler options -# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) -# @param {string} SOURCE_FILES - list of source files -# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) -# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled examples. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/examples/c/example.c b/examples/c/example.c deleted file mode 100644 index 4bc54d5..0000000 --- a/examples/c/example.c +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main( void ) { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 28811f9..0000000 --- a/examples/index.js +++ /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. -*/ - -'use strict'; - -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( './../lib' ); - -var shapes; -var out; -var sh; -var i; -var j; - -function shape2string( shape ) { - return lpad( shape.join( ' x ' ), 20, ' ' ); -} - -shapes = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] -]; - -for ( i = 0; i < shapes.length; i++ ) { - sh = shapes[ i ]; - for ( j = 0; j < sh.length; j++ ) { - console.log( shape2string( sh[ j ] ) ); - } - console.log( lpad( '', 20, '-' ) ); - - out = broadcastShapes( sh ); - console.log( shape2string( out )+'\n' ); -} diff --git a/include/stdlib/ndarray/base/broadcast_shapes.h b/include/stdlib/ndarray/base/broadcast_shapes.h deleted file mode 100644 index 33581cb..0000000 --- a/include/stdlib/ndarray/base/broadcast_shapes.h +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#ifndef STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H -#define STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H - -#include - -/* -* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. -*/ -#ifdef __cplusplus -extern "C" { -#endif - -/** -* Broadcasts array shapes to a single shape. -*/ -int8_t stdlib_ndarray_broadcast_shapes( const int64_t M, const int64_t *shapes[], const int64_t ndims[], int64_t *out ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H diff --git a/index.js b/index.js new file mode 100644 index 0000000..0e33446 --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map new file mode 100644 index 0000000..0c02c0f --- /dev/null +++ b/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 0c9817e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Broadcast array shapes to a single shape. -* -* @module @stdlib/ndarray-base-broadcast-shapes -* -* @example -* var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); -* -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -*/ - -// 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 8558e60..0000000 --- a/lib/main.js +++ /dev/null @@ -1,256 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param {Array} shapes - array of shape arrays -* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`) -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [ 8, 0, 1, 6, 1 ], -* [ 8, 8, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -function broadcastShapes( shapes ) { - var ndims; - var out; - var dim; - var sh; - var n1; - var n2; - var d; - var M; - var N; - var i; - var j; - - M = shapes.length; - out = []; - if ( M === 0 ) { - return out; - } - sh = shapes[ 0 ]; - N = sh.length; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M === 1 ) { - // Need to manually copy to output shape, as shapes could be array-like objects... - for ( i = 0; i < N; i++ ) { - out.push( sh[ i ] ); - } - return out; - } - // Determine the maximum dimensionality... - ndims = [ N ]; - for ( i = 1; i < M; i++ ) { - ndims.push( shapes[ i ].length ); - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Initialize the output array... - for ( i = 0; i < N; i++ ) { - out.push( 0 ); - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim === 1 ) { - dim = d; - continue; - } - if ( d === 1 || dim === d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return null; - } - out[ i ] = dim; - i -= 1; - } - return out; -} - - -// EXPORTS // - -module.exports = broadcastShapes; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 890a937..0000000 --- a/manifest.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "options": {}, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [] - } - ] -} diff --git a/package.json b/package.json index dcdfdb6..a9ff889 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,7 @@ "version": "0.2.2", "description": "Broadcast array shapes to a single shape.", "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", - "include": "./include", - "lib": "./lib", - "src": "./src", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "main": "./index.js", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,33 +12,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/types": "^0.4.3", - "@stdlib/utils-library-manifest": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/string-left-pad": "^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", "stdtypes", @@ -80,9 +27,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 547d921..0000000 --- a/src/main.c +++ /dev/null @@ -1,118 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). -* -* - Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. -* -* @param M number of array shapes -* @param shapes pointer to an array containing shape arrays -* @param ndims array containing the number of dimensions for (i.e., length of) each respective shape array -* @param out pointer to output array -* @return status -* -* @example -* #include "stdlib/ndarray/base/broadcast_shapes.h" -* #include -* -* int64_t N1 = 4; -* int64_t sh1[] = { 8, 1, 6, 1 }; -* -* int64_t N2 = 3; -* int64_t sh2[] = { 7, 1, 5 }; -* -* int64_t ndims[] = { N1, N2 }; -* int64_t *shapes[] = { sh1, sh2 }; -* -* int64_t out[] = { 0, 0, 0, 0 }; -* int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -*/ -int8_t stdlib_ndarray_broadcast_shapes( const int64_t M, const int64_t *shapes[], const int64_t ndims[], int64_t *out ) { - int64_t dim; - const int64_t *sh; - int64_t n1; - int64_t n2; - int64_t d; - int64_t N; - int64_t i; - int64_t j; - - if ( M == 0 ) { - return 0; - } - sh = shapes[ 0 ]; - N = ndims[ 0 ]; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M == 1 ) { - for ( i = 0; i < N; i++ ) { - out[ i ] = sh[ i ]; - } - return 0; - } - // Determine the maximum dimensionality... - for ( i = 1; i < M; i++ ) { - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim == 1 ) { - dim = d; - continue; - } - if ( d == 1 || dim == d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return -1; - } - out[ i ] = dim; - i -= 1; - } - return 0; -} diff --git a/stats_browser.html b/stats_browser.html new file mode 100644 index 0000000..2f35700 --- /dev/null +++ b/stats_browser.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/stats_node.html b/stats_node.html new file mode 100644 index 0000000..c264c7d --- /dev/null +++ b/stats_node.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 63f703c..0000000 --- a/test/test.js +++ /dev/null @@ -1,230 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var broadcastShapes = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastShapes, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] - ]; - - expected = [ - [ 1, 2 ], - [ 3, 4 ], - [ 5, 6, 7 ], - [ 3, 3 ], - [ 3 ], - [ 3, 2 ], - [ 2, 3 ], - [ 1, 2 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty dims)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 0 ], [ 0, 0 ] ], - [ [ 0, 1 ], [ 0, 0 ] ], - [ [ 1, 0 ], [ 0, 1 ] ], - [ [ 1, 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 1, 0 ] ], - [ [ 1, 1 ], [ 0, 1 ] ], - [ [ 0 ], [ 0, 0 ] ], - [ [ 0 ], [ 0, 1 ] ], - [ [ 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 0 ] ], - [ [ 1 ], [ 0, 1 ] ], - [ [ 1 ], [ 1, 0 ] ], - [ [ 1 ], [ 8, 0 ] ], - [ [ 8, 1, 6, 1 ], [ 0, 1, 5 ] ], - [ [ 8, 0, 6, 1 ], [ 1, 5 ] ] - ]; - - expected = [ - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 1, 0 ], - [ 8, 0 ], - [ 8, 0, 6, 5 ], - [ 8, 0, 6, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (no shapes)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [] - ]; - - expected = [ - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty shapes (i.e., zero-dimensional array broadcasting))', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [] ], - [ [], [] ], - [ [], [], [] ], - [ [], [ 0 ] ], - [ [ 0 ], [] ], - [ [], [ 0, 0 ] ], - [ [ 0, 0 ], [] ], - [ [], [ 1, 0 ] ], - [ [], [ 0, 1 ] ], - [ [], [ 3, 3 ] ], - [ [], [ 3, 3 ], [] ] - ]; - - expected = [ - [], - [], - [], - [ 0 ], - [ 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 3, 3 ], - [ 3, 3 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (single shape)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 7 ] ], - [ [ 1, 1 ] ], - [ [ 5, 6, 1 ] ] - ]; - - expected = [ - [ 7 ], - [ 1, 1 ], - [ 5, 6, 1 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function returns `null` if provided incompatible shapes', function test( t ) { - var actual; - var values; - var i; - - values = [ - [ [ 3 ], [ 4 ] ], - [ [ 2, 3 ], [ 2 ] ], - [ [ 3 ], [ 3 ], [ 4 ] ], - [ [ 1, 3, 4 ], [ 2, 3, 3 ] ], - [ [ 1, 2 ], [ 3, 1 ], [ 3, 2 ], [ 10, 5 ] ], - [ [ 2 ], [ 2, 3 ] ], - [ [ 2 ], [ 2 ], [ 2 ], [ 2 ], [ 3 ], [ 3 ], [ 3 ], [ 3 ] ], - [ [ 9, 0, 9 ], [ 0, 9, 0 ] ], - [ [ 9, 9, 9 ], [ 0, 9, 9 ] ], - [ [ 9, 0, 9 ], [ 9, 9, 9 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 0 ] ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.strictEqual( actual, null, 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); From aa363c8abef55c9c41fa4d226546bbd1703d3fa3 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 10 Mar 2025 01:27:59 +0000 Subject: [PATCH 144/158] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 6259d77..dcdfdb6 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,8 @@ }, "dependencies": { "@stdlib/types": "^0.4.3", - "@stdlib/utils-library-manifest": "^0.2.2" + "@stdlib/utils-library-manifest": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, "devDependencies": { "@stdlib/string-left-pad": "^0.2.2", @@ -84,4 +85,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From ce15b582f0e03a0d0939127a2d6f61ae18142c8a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 10 Mar 2025 01:58:11 +0000 Subject: [PATCH 145/158] Remove files --- browser.js | 3 - browser.js.map | 1 - index.js | 3 - index.js.map | 1 - stats_browser.html | 4842 -------------------------------------------- stats_node.html | 4842 -------------------------------------------- 6 files changed, 9692 deletions(-) delete mode 100644 browser.js delete mode 100644 browser.js.map delete mode 100644 index.js delete mode 100644 index.js.map delete mode 100644 stats_browser.html delete mode 100644 stats_node.html diff --git a/browser.js b/browser.js deleted file mode 100644 index 14405dc..0000000 --- a/browser.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); -//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map deleted file mode 100644 index aa4b2bb..0000000 --- a/browser.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"browser.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/index.js b/index.js deleted file mode 100644 index 0e33446..0000000 --- a/index.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); -//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map deleted file mode 100644 index 0c02c0f..0000000 --- a/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/stats_browser.html b/stats_browser.html deleted file mode 100644 index 2f35700..0000000 --- a/stats_browser.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - diff --git a/stats_node.html b/stats_node.html deleted file mode 100644 index c264c7d..0000000 --- a/stats_node.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 8bb9ba1f2b0ba41f1fb5ecf09546a61a6284dda9 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 10 Mar 2025 01:58:31 +0000 Subject: [PATCH 146/158] 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 | 243 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 178 +- SECURITY.md | 5 - benchmark/benchmark.js | 112 - benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 149 - branches.md | 56 - browser.js | 3 + browser.js.map | 1 + dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 39 - docs/types/index.d.ts | 177 - docs/types/test.ts | 45 - examples/c/Makefile | 146 - examples/c/example.c | 50 - examples/index.js | 54 - .../stdlib/ndarray/base/broadcast_shapes.h | 40 - index.js | 3 + index.js.map | 1 + lib/index.js | 45 - lib/main.js | 256 - manifest.json | 38 - package.json | 58 +- src/main.c | 118 - stats_browser.html | 4842 +++++++++++++++++ stats_node.html | 4842 +++++++++++++++++ test/dist/test.js | 33 - test/test.js | 230 - 54 files changed, 9729 insertions(+), 5480 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.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 branches.md create mode 100644 browser.js create mode 100644 browser.js.map 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/index.d.ts delete mode 100644 docs/types/test.ts delete mode 100644 examples/c/Makefile delete mode 100644 examples/c/example.c delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/broadcast_shapes.h create mode 100644 index.js create mode 100644 index.js.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 manifest.json delete mode 100644 src/main.c create mode 100644 stats_browser.html create mode 100644 stats_node.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 a1db025..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2025-03-10T01:19:26.736Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index c8c532b..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 a07d970..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 7292af0..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: '0 12 * * 5' - - # 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 +``` -```javascript -var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); +If no recognized module system is present, access bundle contents via the global scope: + +```html + ``` #### broadcastShapes( shapes ) @@ -245,9 +251,14 @@ var sh = broadcastShapes( [ sh1, sh2 ] ); -```javascript -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); +```html + + + + + + + + ```
@@ -288,131 +304,7 @@ for ( i = 0; i < shapes.length; i++ ) { -* * * - -
- -## C APIs - - - -
- -
- - - - - -
- -### Usage - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -``` - -#### stdlib_ndarray_broadcast_shapes( M, \*\*shapes, \*ndims, \*out ) - -Broadcasts array shapes to a single shape. - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -int64_t N1 = 4; -int64_t sh1[] = { 8, 1, 6, 1 }; - -int64_t N2 = 3; -int64_t sh2[] = { 7, 1, 5 }; - -int64_t ndims[] = { N1, N2 }; -int64_t *shapes[] = { sh1, sh2 }; - -int64_t out[] = { 0, 0, 0, 0 }; -int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -if ( status != 0 ) { - // Handle error... -} -``` - -The function accepts the following arguments: - -- **M**: `[in] int64_t` number of shape arrays. -- **shapes**: `[in] int64_t**` array of shape arrays (dimensions). -- **ndims**: `[in] int64_t*` number of dimensions for each respective shape array. -- **out**: `[out] int64_t*` output shape array. - -```c -int8_t stdlib_ndarray_broadcast_shapes( const int64_t M, const int64_t *shapes[], const int64_t ndims[], int64_t *out ); -``` - -If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). - -
- - - - - -
- -### Notes - -- Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. - -
- - - - - -
- -### Examples - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main( void ) { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} -``` - -
- - - -
- 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.js b/benchmark/benchmark.js deleted file mode 100644 index 6426216..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,112 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pkg = require( './../package.json' ).name; -var broadcastShapes = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::two_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ] ], - [ [ 3, 2 ], [ 3, 1 ] ], - [ [ 1, 1 ], [ 2, 2 ] ], - [ [ 1 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::three_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::four_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ], [ 8, 1, 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ], [ 1, 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ], [ 1, 1, 2, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ], [ 1 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ], [ 5, 1, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/c/Makefile b/benchmark/c/Makefile deleted file mode 100644 index 5dc545c..0000000 --- a/benchmark/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := benchmark.out - - -# RULES # - -#/ -# Compiles C source files. -# -# @param {string} SOURCE_FILES - list of C source files -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lpthread -lblas`) -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [C_COMPILER] - C compiler -# @param {string} [CFLAGS] - C compiler flags -# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} SOURCE_FILES - list of C source files -# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {(string|void)} LIBRARIES - list of libraries (e.g., `-lpthread -lblas`) -# @param {(string|void)} LIBPATH - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} CC - C compiler -# @param {string} CFLAGS - C compiler flags -# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled benchmarks. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/benchmark/c/benchmark.c b/benchmark/c/benchmark.c deleted file mode 100644 index 82d2be5..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,149 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "broadcast-shapes" -#define ITERATIONS 1000000 -#define REPEATS 3 - -/** -* Prints the TAP version. -*/ -static void print_version( void ) { - printf( "TAP version 13\n" ); -} - -/** -* Prints the TAP summary. -* -* @param total total number of tests -* @param passing total number of passing tests -*/ -static void print_summary( int total, int passing ) { - printf( "#\n" ); - printf( "1..%d\n", total ); // TAP plan - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); -} - -/** -* Prints benchmarks results. -* -* @param elapsed elapsed time in seconds -*/ -static void print_results( double elapsed ) { - double rate = (double)ITERATIONS / elapsed; - printf( " ---\n" ); - printf( " iterations: %d\n", ITERATIONS ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", rate ); - printf( " ...\n" ); -} - -/** -* Returns a clock time. -* -* @return clock time -*/ -static double tic( void ) { - struct timeval now; - gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; -} - -/** -* Generates a random number on the interval [0,1). -* -* @return random number -*/ -static double rand_double( void ) { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark( void ) { - double elapsed; - int8_t status; - double t; - int i; - - const int64_t sh1[] = { 8, 1, 6, 1 }; - const int64_t sh2[] = { 7, 1, 5 }; - - const int64_t ndims[] = { 4, 3 }; - const int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( out[ 0 ] != 8 ) { - printf( "unexpected result\n" ); - } - if ( out[ 1 ] != 7 ) { - printf( "unexpected result\n" ); - } - if ( out[ 2 ] != 6 ) { - printf( "unexpected result\n" ); - } - if ( out[ 3 ] != 5 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Main execution sequence. -*/ -int main( void ) { - double elapsed; - int i; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - for ( i = 0; i < REPEATS; i++ ) { - printf( "# c::native::%s::two_arrays\n", NAME ); - elapsed = benchmark(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", i+1 ); - } - print_summary( REPEATS, REPEATS ); -} diff --git a/branches.md b/branches.md deleted file mode 100644 index 79909c9..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes" -%% click B href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/blob/esm/README.md \ No newline at end of file diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..14405dc --- /dev/null +++ b/browser.js @@ -0,0 +1,3 @@ +// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map new file mode 100644 index 0000000..aa4b2bb --- /dev/null +++ b/browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"browser.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 87ea8b6..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import broadcastShapes from '../docs/types/index'; -export = broadcastShapes; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 625741a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var d=function(t,e){return function(){return e||t((e={exports:{}}).exports,e),e.exports}};var h=d(function(x,c){ -function g(t){var e,n,u,o,s,l,a,f,i,r,v;if(f=t.length,n=[],f===0)return n;if(o=t[0],i=o.length,f===1){for(r=0;ri&&(i=e[r]);for(r=0;r=0;){for(s=e[0]-i+r,s>=0?u=o[s]:u=1,v=1;v=0?a=t[v][l]:a=1,u===1){u=a;continue}if(!(a===1||u===a))return null}n[r]=u,r-=1}return n}c.exports=g -});var m=h();module.exports=m; -/** @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 db2949f..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = broadcastShapes;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast array shapes to a single shape.\n*\n* @module @stdlib/ndarray-base-broadcast-shapes\n*\n* @example\n* var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' );\n*\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\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,cAkLA,SAASC,EAAiBC,EAAS,CAClC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GAFAH,EAAIR,EAAO,OACXE,EAAM,CAAC,EACFM,IAAM,EACV,OAAON,EAMR,GAJAE,EAAKJ,EAAQ,CAAE,EACfS,EAAIL,EAAG,OAGFI,IAAM,EAAI,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAI,KAAME,EAAIM,CAAE,CAAE,EAEnB,OAAOR,CACR,CAGA,IADAD,EAAQ,CAAEQ,CAAE,EACNC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAM,KAAMD,EAAQU,CAAE,EAAE,MAAO,EAC1BT,EAAOS,CAAE,EAAID,IACjBA,EAAIR,EAAOS,CAAE,GAIf,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAI,KAAM,CAAE,EAIb,IADAQ,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IANAL,EAAKJ,EAAO,CAAE,EAAIQ,EAAIC,EACjBL,GAAM,EACVF,EAAMC,EAAIC,CAAG,EAEbF,EAAM,EAEDQ,EAAI,EAAGA,EAAIH,EAAGG,IAAM,CAOzB,GANAL,EAAKL,EAAOU,CAAE,EAAIF,EAAIC,EACjBJ,GAAM,EACVC,EAAIP,EAAQW,CAAE,EAAGL,CAAG,EAEpBC,EAAI,EAEAJ,IAAQ,EAAI,CAChBA,EAAMI,EACN,QACD,CACA,GAAK,EAAAA,IAAM,GAAKJ,IAAQI,GAKxB,OAAO,IACR,CACAL,EAAKQ,CAAE,EAAIP,EACXO,GAAK,CACN,CACA,OAAOR,CACR,CAKAJ,EAAO,QAAUC,ICxNjB,IAAIa,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "broadcastShapes", "shapes", "ndims", "out", "dim", "sh", "n1", "n2", "d", "M", "N", "i", "j", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f1d92f6..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,39 +0,0 @@ - -{{alias}}( shapes ) - Broadcasts array shapes to a single shape. - - Two respective dimensions in two shape arrays are compatible if - - 1. the dimensions are equal. - 2. one dimension is `1`. - - The function returns `null` if provided incompatible shapes (i.e., shapes - which cannot be broadcast with one another). - - Parameters - ---------- - shapes: Array - Array of shape arrays. - - Returns - ------- - out: Array|null - Broadcast shape. - - Examples - -------- - // Compatible shapes: - > var sh1 = [ 8, 1, 6, 1 ]; - > var sh2 = [ 7, 1, 5 ]; - > var sh = {{alias}}( [ sh1, sh2 ] ) - [ 8, 7, 6, 5 ] - - // Incompatible shapes: - > sh1 = [ 3, 2 ]; - > sh1 = [ 2, 3 ]; - > sh = {{alias}}( [ sh1, sh2 ] ) - null - - See Also - -------- - diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts deleted file mode 100644 index c2702cf..0000000 --- a/docs/types/index.d.ts +++ /dev/null @@ -1,177 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ArrayLike } from '@stdlib/types/array'; - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param shapes - array shapes -* @returns broadcast shape -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -declare function broadcastShapes( shapes: ArrayLike> ): ArrayLike; - - -// EXPORTS // - -export = broadcastShapes; diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 2886539..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 broadcastShapes = require( './index' ); - - -// TESTS // - -// The function returns an array of numbers... -{ - broadcastShapes( [ [ 1, 2 ], [ 2, 2 ] ] ); // $ExpectType ArrayLike -} - -// The compiler throws an error if the function is not provided an array-like object containing array-like objects containing numbers... -{ - broadcastShapes( '5' ); // $ExpectError - broadcastShapes( 5 ); // $ExpectError - broadcastShapes( true ); // $ExpectError - broadcastShapes( false ); // $ExpectError - broadcastShapes( null ); // $ExpectError - broadcastShapes( {} ); // $ExpectError - broadcastShapes( [ '5' ] ); // $ExpectError - broadcastShapes( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - broadcastShapes(); // $ExpectError - broadcastShapes( [ [ 1, 2, 3 ] ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/c/Makefile b/examples/c/Makefile deleted file mode 100644 index 70c91f4..0000000 --- a/examples/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := example.out - - -# RULES # - -#/ -# Compiles source files. -# -# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) -# @param {string} [CFLAGS] - C compiler options -# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) -# @param {string} [SOURCE_FILES] - list of source files -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} CC - C compiler (e.g., `gcc`) -# @param {string} CFLAGS - C compiler options -# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) -# @param {string} SOURCE_FILES - list of source files -# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) -# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled examples. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/examples/c/example.c b/examples/c/example.c deleted file mode 100644 index 4bc54d5..0000000 --- a/examples/c/example.c +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main( void ) { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 28811f9..0000000 --- a/examples/index.js +++ /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. -*/ - -'use strict'; - -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( './../lib' ); - -var shapes; -var out; -var sh; -var i; -var j; - -function shape2string( shape ) { - return lpad( shape.join( ' x ' ), 20, ' ' ); -} - -shapes = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] -]; - -for ( i = 0; i < shapes.length; i++ ) { - sh = shapes[ i ]; - for ( j = 0; j < sh.length; j++ ) { - console.log( shape2string( sh[ j ] ) ); - } - console.log( lpad( '', 20, '-' ) ); - - out = broadcastShapes( sh ); - console.log( shape2string( out )+'\n' ); -} diff --git a/include/stdlib/ndarray/base/broadcast_shapes.h b/include/stdlib/ndarray/base/broadcast_shapes.h deleted file mode 100644 index 33581cb..0000000 --- a/include/stdlib/ndarray/base/broadcast_shapes.h +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#ifndef STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H -#define STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H - -#include - -/* -* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. -*/ -#ifdef __cplusplus -extern "C" { -#endif - -/** -* Broadcasts array shapes to a single shape. -*/ -int8_t stdlib_ndarray_broadcast_shapes( const int64_t M, const int64_t *shapes[], const int64_t ndims[], int64_t *out ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H diff --git a/index.js b/index.js new file mode 100644 index 0000000..0e33446 --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map new file mode 100644 index 0000000..0c02c0f --- /dev/null +++ b/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 0c9817e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Broadcast array shapes to a single shape. -* -* @module @stdlib/ndarray-base-broadcast-shapes -* -* @example -* var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); -* -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -*/ - -// 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 8558e60..0000000 --- a/lib/main.js +++ /dev/null @@ -1,256 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param {Array} shapes - array of shape arrays -* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`) -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [ 8, 0, 1, 6, 1 ], -* [ 8, 8, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -function broadcastShapes( shapes ) { - var ndims; - var out; - var dim; - var sh; - var n1; - var n2; - var d; - var M; - var N; - var i; - var j; - - M = shapes.length; - out = []; - if ( M === 0 ) { - return out; - } - sh = shapes[ 0 ]; - N = sh.length; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M === 1 ) { - // Need to manually copy to output shape, as shapes could be array-like objects... - for ( i = 0; i < N; i++ ) { - out.push( sh[ i ] ); - } - return out; - } - // Determine the maximum dimensionality... - ndims = [ N ]; - for ( i = 1; i < M; i++ ) { - ndims.push( shapes[ i ].length ); - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Initialize the output array... - for ( i = 0; i < N; i++ ) { - out.push( 0 ); - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim === 1 ) { - dim = d; - continue; - } - if ( d === 1 || dim === d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return null; - } - out[ i ] = dim; - i -= 1; - } - return out; -} - - -// EXPORTS // - -module.exports = broadcastShapes; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 890a937..0000000 --- a/manifest.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "options": {}, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [] - } - ] -} diff --git a/package.json b/package.json index dcdfdb6..a9ff889 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,7 @@ "version": "0.2.2", "description": "Broadcast array shapes to a single shape.", "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", - "include": "./include", - "lib": "./lib", - "src": "./src", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "main": "./index.js", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,33 +12,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/types": "^0.4.3", - "@stdlib/utils-library-manifest": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/string-left-pad": "^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", "stdtypes", @@ -80,9 +27,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 547d921..0000000 --- a/src/main.c +++ /dev/null @@ -1,118 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). -* -* - Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. -* -* @param M number of array shapes -* @param shapes pointer to an array containing shape arrays -* @param ndims array containing the number of dimensions for (i.e., length of) each respective shape array -* @param out pointer to output array -* @return status -* -* @example -* #include "stdlib/ndarray/base/broadcast_shapes.h" -* #include -* -* int64_t N1 = 4; -* int64_t sh1[] = { 8, 1, 6, 1 }; -* -* int64_t N2 = 3; -* int64_t sh2[] = { 7, 1, 5 }; -* -* int64_t ndims[] = { N1, N2 }; -* int64_t *shapes[] = { sh1, sh2 }; -* -* int64_t out[] = { 0, 0, 0, 0 }; -* int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -*/ -int8_t stdlib_ndarray_broadcast_shapes( const int64_t M, const int64_t *shapes[], const int64_t ndims[], int64_t *out ) { - int64_t dim; - const int64_t *sh; - int64_t n1; - int64_t n2; - int64_t d; - int64_t N; - int64_t i; - int64_t j; - - if ( M == 0 ) { - return 0; - } - sh = shapes[ 0 ]; - N = ndims[ 0 ]; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M == 1 ) { - for ( i = 0; i < N; i++ ) { - out[ i ] = sh[ i ]; - } - return 0; - } - // Determine the maximum dimensionality... - for ( i = 1; i < M; i++ ) { - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim == 1 ) { - dim = d; - continue; - } - if ( d == 1 || dim == d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return -1; - } - out[ i ] = dim; - i -= 1; - } - return 0; -} diff --git a/stats_browser.html b/stats_browser.html new file mode 100644 index 0000000..2f35700 --- /dev/null +++ b/stats_browser.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/stats_node.html b/stats_node.html new file mode 100644 index 0000000..c264c7d --- /dev/null +++ b/stats_node.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 63f703c..0000000 --- a/test/test.js +++ /dev/null @@ -1,230 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var broadcastShapes = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastShapes, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] - ]; - - expected = [ - [ 1, 2 ], - [ 3, 4 ], - [ 5, 6, 7 ], - [ 3, 3 ], - [ 3 ], - [ 3, 2 ], - [ 2, 3 ], - [ 1, 2 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty dims)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 0 ], [ 0, 0 ] ], - [ [ 0, 1 ], [ 0, 0 ] ], - [ [ 1, 0 ], [ 0, 1 ] ], - [ [ 1, 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 1, 0 ] ], - [ [ 1, 1 ], [ 0, 1 ] ], - [ [ 0 ], [ 0, 0 ] ], - [ [ 0 ], [ 0, 1 ] ], - [ [ 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 0 ] ], - [ [ 1 ], [ 0, 1 ] ], - [ [ 1 ], [ 1, 0 ] ], - [ [ 1 ], [ 8, 0 ] ], - [ [ 8, 1, 6, 1 ], [ 0, 1, 5 ] ], - [ [ 8, 0, 6, 1 ], [ 1, 5 ] ] - ]; - - expected = [ - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 1, 0 ], - [ 8, 0 ], - [ 8, 0, 6, 5 ], - [ 8, 0, 6, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (no shapes)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [] - ]; - - expected = [ - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty shapes (i.e., zero-dimensional array broadcasting))', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [] ], - [ [], [] ], - [ [], [], [] ], - [ [], [ 0 ] ], - [ [ 0 ], [] ], - [ [], [ 0, 0 ] ], - [ [ 0, 0 ], [] ], - [ [], [ 1, 0 ] ], - [ [], [ 0, 1 ] ], - [ [], [ 3, 3 ] ], - [ [], [ 3, 3 ], [] ] - ]; - - expected = [ - [], - [], - [], - [ 0 ], - [ 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 3, 3 ], - [ 3, 3 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (single shape)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 7 ] ], - [ [ 1, 1 ] ], - [ [ 5, 6, 1 ] ] - ]; - - expected = [ - [ 7 ], - [ 1, 1 ], - [ 5, 6, 1 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function returns `null` if provided incompatible shapes', function test( t ) { - var actual; - var values; - var i; - - values = [ - [ [ 3 ], [ 4 ] ], - [ [ 2, 3 ], [ 2 ] ], - [ [ 3 ], [ 3 ], [ 4 ] ], - [ [ 1, 3, 4 ], [ 2, 3, 3 ] ], - [ [ 1, 2 ], [ 3, 1 ], [ 3, 2 ], [ 10, 5 ] ], - [ [ 2 ], [ 2, 3 ] ], - [ [ 2 ], [ 2 ], [ 2 ], [ 2 ], [ 3 ], [ 3 ], [ 3 ], [ 3 ] ], - [ [ 9, 0, 9 ], [ 0, 9, 0 ] ], - [ [ 9, 9, 9 ], [ 0, 9, 9 ] ], - [ [ 9, 0, 9 ], [ 9, 9, 9 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 0 ] ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.strictEqual( actual, null, 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); From 46915a0cedfd0bf0077f02112ecf30ec5a50b0ab Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 17 Mar 2025 01:35:26 +0000 Subject: [PATCH 147/158] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 6259d77..dcdfdb6 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,8 @@ }, "dependencies": { "@stdlib/types": "^0.4.3", - "@stdlib/utils-library-manifest": "^0.2.2" + "@stdlib/utils-library-manifest": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, "devDependencies": { "@stdlib/string-left-pad": "^0.2.2", @@ -84,4 +85,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From a5d4087d3ffd15544d3de71ab062015790cb5417 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 17 Mar 2025 02:15:43 +0000 Subject: [PATCH 148/158] Remove files --- browser.js | 3 - browser.js.map | 1 - index.js | 3 - index.js.map | 1 - stats_browser.html | 4842 -------------------------------------------- stats_node.html | 4842 -------------------------------------------- 6 files changed, 9692 deletions(-) delete mode 100644 browser.js delete mode 100644 browser.js.map delete mode 100644 index.js delete mode 100644 index.js.map delete mode 100644 stats_browser.html delete mode 100644 stats_node.html diff --git a/browser.js b/browser.js deleted file mode 100644 index 14405dc..0000000 --- a/browser.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); -//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map deleted file mode 100644 index aa4b2bb..0000000 --- a/browser.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"browser.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/index.js b/index.js deleted file mode 100644 index 0e33446..0000000 --- a/index.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); -//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map deleted file mode 100644 index 0c02c0f..0000000 --- a/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/stats_browser.html b/stats_browser.html deleted file mode 100644 index 2f35700..0000000 --- a/stats_browser.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - diff --git a/stats_node.html b/stats_node.html deleted file mode 100644 index c264c7d..0000000 --- a/stats_node.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 21b51a9346fcfce2f05942755ab7b59826b351c5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 17 Mar 2025 02:16:01 +0000 Subject: [PATCH 149/158] 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 | 243 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 178 +- SECURITY.md | 5 - benchmark/benchmark.js | 112 - benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 149 - branches.md | 56 - browser.js | 3 + browser.js.map | 1 + dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 39 - docs/types/index.d.ts | 177 - docs/types/test.ts | 45 - examples/c/Makefile | 146 - examples/c/example.c | 50 - examples/index.js | 54 - .../stdlib/ndarray/base/broadcast_shapes.h | 40 - index.js | 3 + index.js.map | 1 + lib/index.js | 45 - lib/main.js | 256 - manifest.json | 38 - package.json | 58 +- src/main.c | 118 - stats_browser.html | 4842 +++++++++++++++++ stats_node.html | 4842 +++++++++++++++++ test/dist/test.js | 33 - test/test.js | 230 - 54 files changed, 9729 insertions(+), 5480 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.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 branches.md create mode 100644 browser.js create mode 100644 browser.js.map 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/index.d.ts delete mode 100644 docs/types/test.ts delete mode 100644 examples/c/Makefile delete mode 100644 examples/c/example.c delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/broadcast_shapes.h create mode 100644 index.js create mode 100644 index.js.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 manifest.json delete mode 100644 src/main.c create mode 100644 stats_browser.html create mode 100644 stats_node.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 4b135f5..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2025-03-17T01:32:07.185Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index c8c532b..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 a07d970..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 7292af0..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: '0 12 * * 5' - - # 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 +``` -```javascript -var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); +If no recognized module system is present, access bundle contents via the global scope: + +```html + ``` #### broadcastShapes( shapes ) @@ -245,9 +251,14 @@ var sh = broadcastShapes( [ sh1, sh2 ] ); -```javascript -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); +```html + + + + + + + + ```
@@ -288,131 +304,7 @@ for ( i = 0; i < shapes.length; i++ ) { -* * * - -
- -## C APIs - - - -
- -
- - - - - -
- -### Usage - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -``` - -#### stdlib_ndarray_broadcast_shapes( M, \*\*shapes, \*ndims, \*out ) - -Broadcasts array shapes to a single shape. - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -int64_t N1 = 4; -int64_t sh1[] = { 8, 1, 6, 1 }; - -int64_t N2 = 3; -int64_t sh2[] = { 7, 1, 5 }; - -int64_t ndims[] = { N1, N2 }; -int64_t *shapes[] = { sh1, sh2 }; - -int64_t out[] = { 0, 0, 0, 0 }; -int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -if ( status != 0 ) { - // Handle error... -} -``` - -The function accepts the following arguments: - -- **M**: `[in] int64_t` number of shape arrays. -- **shapes**: `[in] int64_t**` array of shape arrays (dimensions). -- **ndims**: `[in] int64_t*` number of dimensions for each respective shape array. -- **out**: `[out] int64_t*` output shape array. - -```c -int8_t stdlib_ndarray_broadcast_shapes( const int64_t M, const int64_t *shapes[], const int64_t ndims[], int64_t *out ); -``` - -If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). - -
- - - - - -
- -### Notes - -- Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. - -
- - - - - -
- -### Examples - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main( void ) { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} -``` - -
- - - -
- 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.js b/benchmark/benchmark.js deleted file mode 100644 index 6426216..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,112 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pkg = require( './../package.json' ).name; -var broadcastShapes = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::two_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ] ], - [ [ 3, 2 ], [ 3, 1 ] ], - [ [ 1, 1 ], [ 2, 2 ] ], - [ [ 1 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::three_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::four_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ], [ 8, 1, 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ], [ 1, 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ], [ 1, 1, 2, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ], [ 1 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ], [ 5, 1, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/c/Makefile b/benchmark/c/Makefile deleted file mode 100644 index 5dc545c..0000000 --- a/benchmark/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := benchmark.out - - -# RULES # - -#/ -# Compiles C source files. -# -# @param {string} SOURCE_FILES - list of C source files -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lpthread -lblas`) -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [C_COMPILER] - C compiler -# @param {string} [CFLAGS] - C compiler flags -# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} SOURCE_FILES - list of C source files -# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {(string|void)} LIBRARIES - list of libraries (e.g., `-lpthread -lblas`) -# @param {(string|void)} LIBPATH - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} CC - C compiler -# @param {string} CFLAGS - C compiler flags -# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled benchmarks. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/benchmark/c/benchmark.c b/benchmark/c/benchmark.c deleted file mode 100644 index 82d2be5..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,149 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "broadcast-shapes" -#define ITERATIONS 1000000 -#define REPEATS 3 - -/** -* Prints the TAP version. -*/ -static void print_version( void ) { - printf( "TAP version 13\n" ); -} - -/** -* Prints the TAP summary. -* -* @param total total number of tests -* @param passing total number of passing tests -*/ -static void print_summary( int total, int passing ) { - printf( "#\n" ); - printf( "1..%d\n", total ); // TAP plan - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); -} - -/** -* Prints benchmarks results. -* -* @param elapsed elapsed time in seconds -*/ -static void print_results( double elapsed ) { - double rate = (double)ITERATIONS / elapsed; - printf( " ---\n" ); - printf( " iterations: %d\n", ITERATIONS ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", rate ); - printf( " ...\n" ); -} - -/** -* Returns a clock time. -* -* @return clock time -*/ -static double tic( void ) { - struct timeval now; - gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; -} - -/** -* Generates a random number on the interval [0,1). -* -* @return random number -*/ -static double rand_double( void ) { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark( void ) { - double elapsed; - int8_t status; - double t; - int i; - - const int64_t sh1[] = { 8, 1, 6, 1 }; - const int64_t sh2[] = { 7, 1, 5 }; - - const int64_t ndims[] = { 4, 3 }; - const int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( out[ 0 ] != 8 ) { - printf( "unexpected result\n" ); - } - if ( out[ 1 ] != 7 ) { - printf( "unexpected result\n" ); - } - if ( out[ 2 ] != 6 ) { - printf( "unexpected result\n" ); - } - if ( out[ 3 ] != 5 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Main execution sequence. -*/ -int main( void ) { - double elapsed; - int i; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - for ( i = 0; i < REPEATS; i++ ) { - printf( "# c::native::%s::two_arrays\n", NAME ); - elapsed = benchmark(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", i+1 ); - } - print_summary( REPEATS, REPEATS ); -} diff --git a/branches.md b/branches.md deleted file mode 100644 index 79909c9..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes" -%% click B href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/blob/esm/README.md \ No newline at end of file diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..14405dc --- /dev/null +++ b/browser.js @@ -0,0 +1,3 @@ +// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map new file mode 100644 index 0000000..aa4b2bb --- /dev/null +++ b/browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"browser.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 87ea8b6..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import broadcastShapes from '../docs/types/index'; -export = broadcastShapes; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 625741a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var d=function(t,e){return function(){return e||t((e={exports:{}}).exports,e),e.exports}};var h=d(function(x,c){ -function g(t){var e,n,u,o,s,l,a,f,i,r,v;if(f=t.length,n=[],f===0)return n;if(o=t[0],i=o.length,f===1){for(r=0;ri&&(i=e[r]);for(r=0;r=0;){for(s=e[0]-i+r,s>=0?u=o[s]:u=1,v=1;v=0?a=t[v][l]:a=1,u===1){u=a;continue}if(!(a===1||u===a))return null}n[r]=u,r-=1}return n}c.exports=g -});var m=h();module.exports=m; -/** @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 db2949f..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = broadcastShapes;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast array shapes to a single shape.\n*\n* @module @stdlib/ndarray-base-broadcast-shapes\n*\n* @example\n* var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' );\n*\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\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,cAkLA,SAASC,EAAiBC,EAAS,CAClC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GAFAH,EAAIR,EAAO,OACXE,EAAM,CAAC,EACFM,IAAM,EACV,OAAON,EAMR,GAJAE,EAAKJ,EAAQ,CAAE,EACfS,EAAIL,EAAG,OAGFI,IAAM,EAAI,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAI,KAAME,EAAIM,CAAE,CAAE,EAEnB,OAAOR,CACR,CAGA,IADAD,EAAQ,CAAEQ,CAAE,EACNC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAM,KAAMD,EAAQU,CAAE,EAAE,MAAO,EAC1BT,EAAOS,CAAE,EAAID,IACjBA,EAAIR,EAAOS,CAAE,GAIf,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAI,KAAM,CAAE,EAIb,IADAQ,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IANAL,EAAKJ,EAAO,CAAE,EAAIQ,EAAIC,EACjBL,GAAM,EACVF,EAAMC,EAAIC,CAAG,EAEbF,EAAM,EAEDQ,EAAI,EAAGA,EAAIH,EAAGG,IAAM,CAOzB,GANAL,EAAKL,EAAOU,CAAE,EAAIF,EAAIC,EACjBJ,GAAM,EACVC,EAAIP,EAAQW,CAAE,EAAGL,CAAG,EAEpBC,EAAI,EAEAJ,IAAQ,EAAI,CAChBA,EAAMI,EACN,QACD,CACA,GAAK,EAAAA,IAAM,GAAKJ,IAAQI,GAKxB,OAAO,IACR,CACAL,EAAKQ,CAAE,EAAIP,EACXO,GAAK,CACN,CACA,OAAOR,CACR,CAKAJ,EAAO,QAAUC,ICxNjB,IAAIa,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "broadcastShapes", "shapes", "ndims", "out", "dim", "sh", "n1", "n2", "d", "M", "N", "i", "j", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f1d92f6..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,39 +0,0 @@ - -{{alias}}( shapes ) - Broadcasts array shapes to a single shape. - - Two respective dimensions in two shape arrays are compatible if - - 1. the dimensions are equal. - 2. one dimension is `1`. - - The function returns `null` if provided incompatible shapes (i.e., shapes - which cannot be broadcast with one another). - - Parameters - ---------- - shapes: Array - Array of shape arrays. - - Returns - ------- - out: Array|null - Broadcast shape. - - Examples - -------- - // Compatible shapes: - > var sh1 = [ 8, 1, 6, 1 ]; - > var sh2 = [ 7, 1, 5 ]; - > var sh = {{alias}}( [ sh1, sh2 ] ) - [ 8, 7, 6, 5 ] - - // Incompatible shapes: - > sh1 = [ 3, 2 ]; - > sh1 = [ 2, 3 ]; - > sh = {{alias}}( [ sh1, sh2 ] ) - null - - See Also - -------- - diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts deleted file mode 100644 index c2702cf..0000000 --- a/docs/types/index.d.ts +++ /dev/null @@ -1,177 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ArrayLike } from '@stdlib/types/array'; - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param shapes - array shapes -* @returns broadcast shape -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -declare function broadcastShapes( shapes: ArrayLike> ): ArrayLike; - - -// EXPORTS // - -export = broadcastShapes; diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 2886539..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 broadcastShapes = require( './index' ); - - -// TESTS // - -// The function returns an array of numbers... -{ - broadcastShapes( [ [ 1, 2 ], [ 2, 2 ] ] ); // $ExpectType ArrayLike -} - -// The compiler throws an error if the function is not provided an array-like object containing array-like objects containing numbers... -{ - broadcastShapes( '5' ); // $ExpectError - broadcastShapes( 5 ); // $ExpectError - broadcastShapes( true ); // $ExpectError - broadcastShapes( false ); // $ExpectError - broadcastShapes( null ); // $ExpectError - broadcastShapes( {} ); // $ExpectError - broadcastShapes( [ '5' ] ); // $ExpectError - broadcastShapes( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - broadcastShapes(); // $ExpectError - broadcastShapes( [ [ 1, 2, 3 ] ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/c/Makefile b/examples/c/Makefile deleted file mode 100644 index 70c91f4..0000000 --- a/examples/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := example.out - - -# RULES # - -#/ -# Compiles source files. -# -# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) -# @param {string} [CFLAGS] - C compiler options -# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) -# @param {string} [SOURCE_FILES] - list of source files -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} CC - C compiler (e.g., `gcc`) -# @param {string} CFLAGS - C compiler options -# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) -# @param {string} SOURCE_FILES - list of source files -# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) -# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled examples. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/examples/c/example.c b/examples/c/example.c deleted file mode 100644 index 4bc54d5..0000000 --- a/examples/c/example.c +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main( void ) { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 28811f9..0000000 --- a/examples/index.js +++ /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. -*/ - -'use strict'; - -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( './../lib' ); - -var shapes; -var out; -var sh; -var i; -var j; - -function shape2string( shape ) { - return lpad( shape.join( ' x ' ), 20, ' ' ); -} - -shapes = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] -]; - -for ( i = 0; i < shapes.length; i++ ) { - sh = shapes[ i ]; - for ( j = 0; j < sh.length; j++ ) { - console.log( shape2string( sh[ j ] ) ); - } - console.log( lpad( '', 20, '-' ) ); - - out = broadcastShapes( sh ); - console.log( shape2string( out )+'\n' ); -} diff --git a/include/stdlib/ndarray/base/broadcast_shapes.h b/include/stdlib/ndarray/base/broadcast_shapes.h deleted file mode 100644 index 33581cb..0000000 --- a/include/stdlib/ndarray/base/broadcast_shapes.h +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#ifndef STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H -#define STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H - -#include - -/* -* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. -*/ -#ifdef __cplusplus -extern "C" { -#endif - -/** -* Broadcasts array shapes to a single shape. -*/ -int8_t stdlib_ndarray_broadcast_shapes( const int64_t M, const int64_t *shapes[], const int64_t ndims[], int64_t *out ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H diff --git a/index.js b/index.js new file mode 100644 index 0000000..0e33446 --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map new file mode 100644 index 0000000..0c02c0f --- /dev/null +++ b/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 0c9817e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Broadcast array shapes to a single shape. -* -* @module @stdlib/ndarray-base-broadcast-shapes -* -* @example -* var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); -* -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -*/ - -// 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 8558e60..0000000 --- a/lib/main.js +++ /dev/null @@ -1,256 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param {Array} shapes - array of shape arrays -* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`) -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [ 8, 0, 1, 6, 1 ], -* [ 8, 8, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -function broadcastShapes( shapes ) { - var ndims; - var out; - var dim; - var sh; - var n1; - var n2; - var d; - var M; - var N; - var i; - var j; - - M = shapes.length; - out = []; - if ( M === 0 ) { - return out; - } - sh = shapes[ 0 ]; - N = sh.length; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M === 1 ) { - // Need to manually copy to output shape, as shapes could be array-like objects... - for ( i = 0; i < N; i++ ) { - out.push( sh[ i ] ); - } - return out; - } - // Determine the maximum dimensionality... - ndims = [ N ]; - for ( i = 1; i < M; i++ ) { - ndims.push( shapes[ i ].length ); - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Initialize the output array... - for ( i = 0; i < N; i++ ) { - out.push( 0 ); - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim === 1 ) { - dim = d; - continue; - } - if ( d === 1 || dim === d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return null; - } - out[ i ] = dim; - i -= 1; - } - return out; -} - - -// EXPORTS // - -module.exports = broadcastShapes; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 890a937..0000000 --- a/manifest.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "options": {}, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [] - } - ] -} diff --git a/package.json b/package.json index dcdfdb6..a9ff889 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,7 @@ "version": "0.2.2", "description": "Broadcast array shapes to a single shape.", "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", - "include": "./include", - "lib": "./lib", - "src": "./src", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "main": "./index.js", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,33 +12,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/types": "^0.4.3", - "@stdlib/utils-library-manifest": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/string-left-pad": "^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", "stdtypes", @@ -80,9 +27,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 547d921..0000000 --- a/src/main.c +++ /dev/null @@ -1,118 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). -* -* - Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. -* -* @param M number of array shapes -* @param shapes pointer to an array containing shape arrays -* @param ndims array containing the number of dimensions for (i.e., length of) each respective shape array -* @param out pointer to output array -* @return status -* -* @example -* #include "stdlib/ndarray/base/broadcast_shapes.h" -* #include -* -* int64_t N1 = 4; -* int64_t sh1[] = { 8, 1, 6, 1 }; -* -* int64_t N2 = 3; -* int64_t sh2[] = { 7, 1, 5 }; -* -* int64_t ndims[] = { N1, N2 }; -* int64_t *shapes[] = { sh1, sh2 }; -* -* int64_t out[] = { 0, 0, 0, 0 }; -* int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -*/ -int8_t stdlib_ndarray_broadcast_shapes( const int64_t M, const int64_t *shapes[], const int64_t ndims[], int64_t *out ) { - int64_t dim; - const int64_t *sh; - int64_t n1; - int64_t n2; - int64_t d; - int64_t N; - int64_t i; - int64_t j; - - if ( M == 0 ) { - return 0; - } - sh = shapes[ 0 ]; - N = ndims[ 0 ]; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M == 1 ) { - for ( i = 0; i < N; i++ ) { - out[ i ] = sh[ i ]; - } - return 0; - } - // Determine the maximum dimensionality... - for ( i = 1; i < M; i++ ) { - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim == 1 ) { - dim = d; - continue; - } - if ( d == 1 || dim == d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return -1; - } - out[ i ] = dim; - i -= 1; - } - return 0; -} diff --git a/stats_browser.html b/stats_browser.html new file mode 100644 index 0000000..2f35700 --- /dev/null +++ b/stats_browser.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/stats_node.html b/stats_node.html new file mode 100644 index 0000000..c264c7d --- /dev/null +++ b/stats_node.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 63f703c..0000000 --- a/test/test.js +++ /dev/null @@ -1,230 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var broadcastShapes = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastShapes, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] - ]; - - expected = [ - [ 1, 2 ], - [ 3, 4 ], - [ 5, 6, 7 ], - [ 3, 3 ], - [ 3 ], - [ 3, 2 ], - [ 2, 3 ], - [ 1, 2 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty dims)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 0 ], [ 0, 0 ] ], - [ [ 0, 1 ], [ 0, 0 ] ], - [ [ 1, 0 ], [ 0, 1 ] ], - [ [ 1, 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 1, 0 ] ], - [ [ 1, 1 ], [ 0, 1 ] ], - [ [ 0 ], [ 0, 0 ] ], - [ [ 0 ], [ 0, 1 ] ], - [ [ 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 0 ] ], - [ [ 1 ], [ 0, 1 ] ], - [ [ 1 ], [ 1, 0 ] ], - [ [ 1 ], [ 8, 0 ] ], - [ [ 8, 1, 6, 1 ], [ 0, 1, 5 ] ], - [ [ 8, 0, 6, 1 ], [ 1, 5 ] ] - ]; - - expected = [ - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 1, 0 ], - [ 8, 0 ], - [ 8, 0, 6, 5 ], - [ 8, 0, 6, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (no shapes)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [] - ]; - - expected = [ - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty shapes (i.e., zero-dimensional array broadcasting))', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [] ], - [ [], [] ], - [ [], [], [] ], - [ [], [ 0 ] ], - [ [ 0 ], [] ], - [ [], [ 0, 0 ] ], - [ [ 0, 0 ], [] ], - [ [], [ 1, 0 ] ], - [ [], [ 0, 1 ] ], - [ [], [ 3, 3 ] ], - [ [], [ 3, 3 ], [] ] - ]; - - expected = [ - [], - [], - [], - [ 0 ], - [ 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 3, 3 ], - [ 3, 3 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (single shape)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 7 ] ], - [ [ 1, 1 ] ], - [ [ 5, 6, 1 ] ] - ]; - - expected = [ - [ 7 ], - [ 1, 1 ], - [ 5, 6, 1 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function returns `null` if provided incompatible shapes', function test( t ) { - var actual; - var values; - var i; - - values = [ - [ [ 3 ], [ 4 ] ], - [ [ 2, 3 ], [ 2 ] ], - [ [ 3 ], [ 3 ], [ 4 ] ], - [ [ 1, 3, 4 ], [ 2, 3, 3 ] ], - [ [ 1, 2 ], [ 3, 1 ], [ 3, 2 ], [ 10, 5 ] ], - [ [ 2 ], [ 2, 3 ] ], - [ [ 2 ], [ 2 ], [ 2 ], [ 2 ], [ 3 ], [ 3 ], [ 3 ], [ 3 ] ], - [ [ 9, 0, 9 ], [ 0, 9, 0 ] ], - [ [ 9, 9, 9 ], [ 0, 9, 9 ] ], - [ [ 9, 0, 9 ], [ 9, 9, 9 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 0 ] ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.strictEqual( actual, null, 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); From c9823d62804f9a3b6dd34c756baebb8996dba82a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 30 May 2025 23:34:05 +0000 Subject: [PATCH 150/158] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 6259d77..dcdfdb6 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,8 @@ }, "dependencies": { "@stdlib/types": "^0.4.3", - "@stdlib/utils-library-manifest": "^0.2.2" + "@stdlib/utils-library-manifest": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, "devDependencies": { "@stdlib/string-left-pad": "^0.2.2", @@ -84,4 +85,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From dd5aac9069c3362ef15e11e6d844e94a02b35350 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 30 May 2025 23:34:28 +0000 Subject: [PATCH 151/158] Remove files --- browser.js | 3 - browser.js.map | 1 - index.js | 3 - index.js.map | 1 - stats_browser.html | 4842 -------------------------------------------- stats_node.html | 4842 -------------------------------------------- 6 files changed, 9692 deletions(-) delete mode 100644 browser.js delete mode 100644 browser.js.map delete mode 100644 index.js delete mode 100644 index.js.map delete mode 100644 stats_browser.html delete mode 100644 stats_node.html diff --git a/browser.js b/browser.js deleted file mode 100644 index 14405dc..0000000 --- a/browser.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); -//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map deleted file mode 100644 index aa4b2bb..0000000 --- a/browser.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"browser.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/index.js b/index.js deleted file mode 100644 index 0e33446..0000000 --- a/index.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); -//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map deleted file mode 100644 index 0c02c0f..0000000 --- a/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/stats_browser.html b/stats_browser.html deleted file mode 100644 index 2f35700..0000000 --- a/stats_browser.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - diff --git a/stats_node.html b/stats_node.html deleted file mode 100644 index c264c7d..0000000 --- a/stats_node.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From a396d91959b0d30868d9bfa6d855e75a7a37de54 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 30 May 2025 23:35:05 +0000 Subject: [PATCH 152/158] Auto-generated commit --- .editorconfig | 180 - .eslintrc.js | 1 - .gitattributes | 66 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 194 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 257 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 178 +- SECURITY.md | 5 - benchmark/benchmark.js | 112 - benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 149 - branches.md | 56 - browser.js | 3 + browser.js.map | 1 + dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 39 - docs/types/index.d.ts | 177 - docs/types/test.ts | 45 - examples/c/Makefile | 146 - examples/c/example.c | 50 - examples/index.js | 54 - .../stdlib/ndarray/base/broadcast_shapes.h | 40 - index.js | 3 + index.js.map | 1 + lib/index.js | 45 - lib/main.js | 256 - manifest.json | 38 - package.json | 58 +- src/main.c | 118 - stats_browser.html | 4842 +++++++++++++++++ stats_node.html | 4842 +++++++++++++++++ test/dist/test.js | 33 - test/test.js | 230 - 53 files changed, 9729 insertions(+), 5493 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 branches.md create mode 100644 browser.js create mode 100644 browser.js.map 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/index.d.ts delete mode 100644 docs/types/test.ts delete mode 100644 examples/c/Makefile delete mode 100644 examples/c/example.c delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/broadcast_shapes.h create mode 100644 index.js create mode 100644 index.js.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 manifest.json delete mode 100644 src/main.c create mode 100644 stats_browser.html create mode 100644 stats_node.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/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index c8c532b..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 a07d970..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 7292af0..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: '0 12 * * 5' - - # 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 +``` -```javascript -var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); +If no recognized module system is present, access bundle contents via the global scope: + +```html + ``` #### broadcastShapes( shapes ) @@ -245,9 +251,14 @@ var sh = broadcastShapes( [ sh1, sh2 ] ); -```javascript -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); +```html + + + + + + + + ```
@@ -288,131 +304,7 @@ for ( i = 0; i < shapes.length; i++ ) { -* * * - -
- -## C APIs - - - -
- -
- - - - - -
- -### Usage - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -``` - -#### stdlib_ndarray_broadcast_shapes( M, \*\*shapes, \*ndims, \*out ) - -Broadcasts array shapes to a single shape. - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -int64_t N1 = 4; -int64_t sh1[] = { 8, 1, 6, 1 }; - -int64_t N2 = 3; -int64_t sh2[] = { 7, 1, 5 }; - -int64_t ndims[] = { N1, N2 }; -int64_t *shapes[] = { sh1, sh2 }; - -int64_t out[] = { 0, 0, 0, 0 }; -int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -if ( status != 0 ) { - // Handle error... -} -``` - -The function accepts the following arguments: - -- **M**: `[in] int64_t` number of shape arrays. -- **shapes**: `[in] int64_t**` array of shape arrays (dimensions). -- **ndims**: `[in] int64_t*` number of dimensions for each respective shape array. -- **out**: `[out] int64_t*` output shape array. - -```c -int8_t stdlib_ndarray_broadcast_shapes( const int64_t M, const int64_t *shapes[], const int64_t ndims[], int64_t *out ); -``` - -If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). - -
- - - - - -
- -### Notes - -- Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. - -
- - - - - -
- -### Examples - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main( void ) { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} -``` - -
- - - -
- 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.js b/benchmark/benchmark.js deleted file mode 100644 index 6426216..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,112 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pkg = require( './../package.json' ).name; -var broadcastShapes = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::two_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ] ], - [ [ 3, 2 ], [ 3, 1 ] ], - [ [ 1, 1 ], [ 2, 2 ] ], - [ [ 1 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::three_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::four_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ], [ 8, 1, 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ], [ 1, 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ], [ 1, 1, 2, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ], [ 1 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ], [ 5, 1, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/c/Makefile b/benchmark/c/Makefile deleted file mode 100644 index 5dc545c..0000000 --- a/benchmark/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := benchmark.out - - -# RULES # - -#/ -# Compiles C source files. -# -# @param {string} SOURCE_FILES - list of C source files -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lpthread -lblas`) -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [C_COMPILER] - C compiler -# @param {string} [CFLAGS] - C compiler flags -# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} SOURCE_FILES - list of C source files -# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {(string|void)} LIBRARIES - list of libraries (e.g., `-lpthread -lblas`) -# @param {(string|void)} LIBPATH - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} CC - C compiler -# @param {string} CFLAGS - C compiler flags -# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled benchmarks. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/benchmark/c/benchmark.c b/benchmark/c/benchmark.c deleted file mode 100644 index 82d2be5..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,149 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "broadcast-shapes" -#define ITERATIONS 1000000 -#define REPEATS 3 - -/** -* Prints the TAP version. -*/ -static void print_version( void ) { - printf( "TAP version 13\n" ); -} - -/** -* Prints the TAP summary. -* -* @param total total number of tests -* @param passing total number of passing tests -*/ -static void print_summary( int total, int passing ) { - printf( "#\n" ); - printf( "1..%d\n", total ); // TAP plan - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); -} - -/** -* Prints benchmarks results. -* -* @param elapsed elapsed time in seconds -*/ -static void print_results( double elapsed ) { - double rate = (double)ITERATIONS / elapsed; - printf( " ---\n" ); - printf( " iterations: %d\n", ITERATIONS ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", rate ); - printf( " ...\n" ); -} - -/** -* Returns a clock time. -* -* @return clock time -*/ -static double tic( void ) { - struct timeval now; - gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; -} - -/** -* Generates a random number on the interval [0,1). -* -* @return random number -*/ -static double rand_double( void ) { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark( void ) { - double elapsed; - int8_t status; - double t; - int i; - - const int64_t sh1[] = { 8, 1, 6, 1 }; - const int64_t sh2[] = { 7, 1, 5 }; - - const int64_t ndims[] = { 4, 3 }; - const int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( out[ 0 ] != 8 ) { - printf( "unexpected result\n" ); - } - if ( out[ 1 ] != 7 ) { - printf( "unexpected result\n" ); - } - if ( out[ 2 ] != 6 ) { - printf( "unexpected result\n" ); - } - if ( out[ 3 ] != 5 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Main execution sequence. -*/ -int main( void ) { - double elapsed; - int i; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - for ( i = 0; i < REPEATS; i++ ) { - printf( "# c::native::%s::two_arrays\n", NAME ); - elapsed = benchmark(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", i+1 ); - } - print_summary( REPEATS, REPEATS ); -} diff --git a/branches.md b/branches.md deleted file mode 100644 index 79909c9..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes" -%% click B href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/blob/esm/README.md \ No newline at end of file diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..14405dc --- /dev/null +++ b/browser.js @@ -0,0 +1,3 @@ +// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map new file mode 100644 index 0000000..aa4b2bb --- /dev/null +++ b/browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"browser.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 87ea8b6..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import broadcastShapes from '../docs/types/index'; -export = broadcastShapes; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 625741a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var d=function(t,e){return function(){return e||t((e={exports:{}}).exports,e),e.exports}};var h=d(function(x,c){ -function g(t){var e,n,u,o,s,l,a,f,i,r,v;if(f=t.length,n=[],f===0)return n;if(o=t[0],i=o.length,f===1){for(r=0;ri&&(i=e[r]);for(r=0;r=0;){for(s=e[0]-i+r,s>=0?u=o[s]:u=1,v=1;v=0?a=t[v][l]:a=1,u===1){u=a;continue}if(!(a===1||u===a))return null}n[r]=u,r-=1}return n}c.exports=g -});var m=h();module.exports=m; -/** @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 db2949f..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = broadcastShapes;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast array shapes to a single shape.\n*\n* @module @stdlib/ndarray-base-broadcast-shapes\n*\n* @example\n* var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' );\n*\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\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,cAkLA,SAASC,EAAiBC,EAAS,CAClC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GAFAH,EAAIR,EAAO,OACXE,EAAM,CAAC,EACFM,IAAM,EACV,OAAON,EAMR,GAJAE,EAAKJ,EAAQ,CAAE,EACfS,EAAIL,EAAG,OAGFI,IAAM,EAAI,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAI,KAAME,EAAIM,CAAE,CAAE,EAEnB,OAAOR,CACR,CAGA,IADAD,EAAQ,CAAEQ,CAAE,EACNC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAM,KAAMD,EAAQU,CAAE,EAAE,MAAO,EAC1BT,EAAOS,CAAE,EAAID,IACjBA,EAAIR,EAAOS,CAAE,GAIf,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAI,KAAM,CAAE,EAIb,IADAQ,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IANAL,EAAKJ,EAAO,CAAE,EAAIQ,EAAIC,EACjBL,GAAM,EACVF,EAAMC,EAAIC,CAAG,EAEbF,EAAM,EAEDQ,EAAI,EAAGA,EAAIH,EAAGG,IAAM,CAOzB,GANAL,EAAKL,EAAOU,CAAE,EAAIF,EAAIC,EACjBJ,GAAM,EACVC,EAAIP,EAAQW,CAAE,EAAGL,CAAG,EAEpBC,EAAI,EAEAJ,IAAQ,EAAI,CAChBA,EAAMI,EACN,QACD,CACA,GAAK,EAAAA,IAAM,GAAKJ,IAAQI,GAKxB,OAAO,IACR,CACAL,EAAKQ,CAAE,EAAIP,EACXO,GAAK,CACN,CACA,OAAOR,CACR,CAKAJ,EAAO,QAAUC,ICxNjB,IAAIa,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "broadcastShapes", "shapes", "ndims", "out", "dim", "sh", "n1", "n2", "d", "M", "N", "i", "j", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f1d92f6..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,39 +0,0 @@ - -{{alias}}( shapes ) - Broadcasts array shapes to a single shape. - - Two respective dimensions in two shape arrays are compatible if - - 1. the dimensions are equal. - 2. one dimension is `1`. - - The function returns `null` if provided incompatible shapes (i.e., shapes - which cannot be broadcast with one another). - - Parameters - ---------- - shapes: Array - Array of shape arrays. - - Returns - ------- - out: Array|null - Broadcast shape. - - Examples - -------- - // Compatible shapes: - > var sh1 = [ 8, 1, 6, 1 ]; - > var sh2 = [ 7, 1, 5 ]; - > var sh = {{alias}}( [ sh1, sh2 ] ) - [ 8, 7, 6, 5 ] - - // Incompatible shapes: - > sh1 = [ 3, 2 ]; - > sh1 = [ 2, 3 ]; - > sh = {{alias}}( [ sh1, sh2 ] ) - null - - See Also - -------- - diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts deleted file mode 100644 index c2702cf..0000000 --- a/docs/types/index.d.ts +++ /dev/null @@ -1,177 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ArrayLike } from '@stdlib/types/array'; - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param shapes - array shapes -* @returns broadcast shape -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -declare function broadcastShapes( shapes: ArrayLike> ): ArrayLike; - - -// EXPORTS // - -export = broadcastShapes; diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 2886539..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 broadcastShapes = require( './index' ); - - -// TESTS // - -// The function returns an array of numbers... -{ - broadcastShapes( [ [ 1, 2 ], [ 2, 2 ] ] ); // $ExpectType ArrayLike -} - -// The compiler throws an error if the function is not provided an array-like object containing array-like objects containing numbers... -{ - broadcastShapes( '5' ); // $ExpectError - broadcastShapes( 5 ); // $ExpectError - broadcastShapes( true ); // $ExpectError - broadcastShapes( false ); // $ExpectError - broadcastShapes( null ); // $ExpectError - broadcastShapes( {} ); // $ExpectError - broadcastShapes( [ '5' ] ); // $ExpectError - broadcastShapes( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - broadcastShapes(); // $ExpectError - broadcastShapes( [ [ 1, 2, 3 ] ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/c/Makefile b/examples/c/Makefile deleted file mode 100644 index 70c91f4..0000000 --- a/examples/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := example.out - - -# RULES # - -#/ -# Compiles source files. -# -# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) -# @param {string} [CFLAGS] - C compiler options -# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) -# @param {string} [SOURCE_FILES] - list of source files -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} CC - C compiler (e.g., `gcc`) -# @param {string} CFLAGS - C compiler options -# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) -# @param {string} SOURCE_FILES - list of source files -# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) -# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled examples. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/examples/c/example.c b/examples/c/example.c deleted file mode 100644 index 4bc54d5..0000000 --- a/examples/c/example.c +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main( void ) { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 28811f9..0000000 --- a/examples/index.js +++ /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. -*/ - -'use strict'; - -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( './../lib' ); - -var shapes; -var out; -var sh; -var i; -var j; - -function shape2string( shape ) { - return lpad( shape.join( ' x ' ), 20, ' ' ); -} - -shapes = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] -]; - -for ( i = 0; i < shapes.length; i++ ) { - sh = shapes[ i ]; - for ( j = 0; j < sh.length; j++ ) { - console.log( shape2string( sh[ j ] ) ); - } - console.log( lpad( '', 20, '-' ) ); - - out = broadcastShapes( sh ); - console.log( shape2string( out )+'\n' ); -} diff --git a/include/stdlib/ndarray/base/broadcast_shapes.h b/include/stdlib/ndarray/base/broadcast_shapes.h deleted file mode 100644 index 33581cb..0000000 --- a/include/stdlib/ndarray/base/broadcast_shapes.h +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#ifndef STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H -#define STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H - -#include - -/* -* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. -*/ -#ifdef __cplusplus -extern "C" { -#endif - -/** -* Broadcasts array shapes to a single shape. -*/ -int8_t stdlib_ndarray_broadcast_shapes( const int64_t M, const int64_t *shapes[], const int64_t ndims[], int64_t *out ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H diff --git a/index.js b/index.js new file mode 100644 index 0000000..0e33446 --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map new file mode 100644 index 0000000..0c02c0f --- /dev/null +++ b/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 0c9817e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Broadcast array shapes to a single shape. -* -* @module @stdlib/ndarray-base-broadcast-shapes -* -* @example -* var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); -* -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -*/ - -// 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 8558e60..0000000 --- a/lib/main.js +++ /dev/null @@ -1,256 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param {Array} shapes - array of shape arrays -* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`) -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [ 8, 0, 1, 6, 1 ], -* [ 8, 8, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -function broadcastShapes( shapes ) { - var ndims; - var out; - var dim; - var sh; - var n1; - var n2; - var d; - var M; - var N; - var i; - var j; - - M = shapes.length; - out = []; - if ( M === 0 ) { - return out; - } - sh = shapes[ 0 ]; - N = sh.length; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M === 1 ) { - // Need to manually copy to output shape, as shapes could be array-like objects... - for ( i = 0; i < N; i++ ) { - out.push( sh[ i ] ); - } - return out; - } - // Determine the maximum dimensionality... - ndims = [ N ]; - for ( i = 1; i < M; i++ ) { - ndims.push( shapes[ i ].length ); - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Initialize the output array... - for ( i = 0; i < N; i++ ) { - out.push( 0 ); - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim === 1 ) { - dim = d; - continue; - } - if ( d === 1 || dim === d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return null; - } - out[ i ] = dim; - i -= 1; - } - return out; -} - - -// EXPORTS // - -module.exports = broadcastShapes; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 04e61e3..0000000 --- a/manifest.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "options": {}, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [] - } - ] -} diff --git a/package.json b/package.json index dcdfdb6..a9ff889 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,7 @@ "version": "0.2.2", "description": "Broadcast array shapes to a single shape.", "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", - "include": "./include", - "lib": "./lib", - "src": "./src", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "main": "./index.js", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,33 +12,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/types": "^0.4.3", - "@stdlib/utils-library-manifest": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/string-left-pad": "^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", "stdtypes", @@ -80,9 +27,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 547d921..0000000 --- a/src/main.c +++ /dev/null @@ -1,118 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). -* -* - Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. -* -* @param M number of array shapes -* @param shapes pointer to an array containing shape arrays -* @param ndims array containing the number of dimensions for (i.e., length of) each respective shape array -* @param out pointer to output array -* @return status -* -* @example -* #include "stdlib/ndarray/base/broadcast_shapes.h" -* #include -* -* int64_t N1 = 4; -* int64_t sh1[] = { 8, 1, 6, 1 }; -* -* int64_t N2 = 3; -* int64_t sh2[] = { 7, 1, 5 }; -* -* int64_t ndims[] = { N1, N2 }; -* int64_t *shapes[] = { sh1, sh2 }; -* -* int64_t out[] = { 0, 0, 0, 0 }; -* int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -*/ -int8_t stdlib_ndarray_broadcast_shapes( const int64_t M, const int64_t *shapes[], const int64_t ndims[], int64_t *out ) { - int64_t dim; - const int64_t *sh; - int64_t n1; - int64_t n2; - int64_t d; - int64_t N; - int64_t i; - int64_t j; - - if ( M == 0 ) { - return 0; - } - sh = shapes[ 0 ]; - N = ndims[ 0 ]; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M == 1 ) { - for ( i = 0; i < N; i++ ) { - out[ i ] = sh[ i ]; - } - return 0; - } - // Determine the maximum dimensionality... - for ( i = 1; i < M; i++ ) { - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim == 1 ) { - dim = d; - continue; - } - if ( d == 1 || dim == d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return -1; - } - out[ i ] = dim; - i -= 1; - } - return 0; -} diff --git a/stats_browser.html b/stats_browser.html new file mode 100644 index 0000000..2f35700 --- /dev/null +++ b/stats_browser.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/stats_node.html b/stats_node.html new file mode 100644 index 0000000..c264c7d --- /dev/null +++ b/stats_node.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 63f703c..0000000 --- a/test/test.js +++ /dev/null @@ -1,230 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var broadcastShapes = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastShapes, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] - ]; - - expected = [ - [ 1, 2 ], - [ 3, 4 ], - [ 5, 6, 7 ], - [ 3, 3 ], - [ 3 ], - [ 3, 2 ], - [ 2, 3 ], - [ 1, 2 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty dims)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 0 ], [ 0, 0 ] ], - [ [ 0, 1 ], [ 0, 0 ] ], - [ [ 1, 0 ], [ 0, 1 ] ], - [ [ 1, 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 1, 0 ] ], - [ [ 1, 1 ], [ 0, 1 ] ], - [ [ 0 ], [ 0, 0 ] ], - [ [ 0 ], [ 0, 1 ] ], - [ [ 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 0 ] ], - [ [ 1 ], [ 0, 1 ] ], - [ [ 1 ], [ 1, 0 ] ], - [ [ 1 ], [ 8, 0 ] ], - [ [ 8, 1, 6, 1 ], [ 0, 1, 5 ] ], - [ [ 8, 0, 6, 1 ], [ 1, 5 ] ] - ]; - - expected = [ - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 1, 0 ], - [ 8, 0 ], - [ 8, 0, 6, 5 ], - [ 8, 0, 6, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (no shapes)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [] - ]; - - expected = [ - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty shapes (i.e., zero-dimensional array broadcasting))', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [] ], - [ [], [] ], - [ [], [], [] ], - [ [], [ 0 ] ], - [ [ 0 ], [] ], - [ [], [ 0, 0 ] ], - [ [ 0, 0 ], [] ], - [ [], [ 1, 0 ] ], - [ [], [ 0, 1 ] ], - [ [], [ 3, 3 ] ], - [ [], [ 3, 3 ], [] ] - ]; - - expected = [ - [], - [], - [], - [ 0 ], - [ 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 3, 3 ], - [ 3, 3 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (single shape)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 7 ] ], - [ [ 1, 1 ] ], - [ [ 5, 6, 1 ] ] - ]; - - expected = [ - [ 7 ], - [ 1, 1 ], - [ 5, 6, 1 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function returns `null` if provided incompatible shapes', function test( t ) { - var actual; - var values; - var i; - - values = [ - [ [ 3 ], [ 4 ] ], - [ [ 2, 3 ], [ 2 ] ], - [ [ 3 ], [ 3 ], [ 4 ] ], - [ [ 1, 3, 4 ], [ 2, 3, 3 ] ], - [ [ 1, 2 ], [ 3, 1 ], [ 3, 2 ], [ 10, 5 ] ], - [ [ 2 ], [ 2, 3 ] ], - [ [ 2 ], [ 2 ], [ 2 ], [ 2 ], [ 3 ], [ 3 ], [ 3 ], [ 3 ] ], - [ [ 9, 0, 9 ], [ 0, 9, 0 ] ], - [ [ 9, 9, 9 ], [ 0, 9, 9 ] ], - [ [ 9, 0, 9 ], [ 9, 9, 9 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 0 ] ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.strictEqual( actual, null, 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); From 31b72c6ea5b15edd69ac00bd77ad72d5356d0fd7 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 30 Jun 2025 01:42:03 +0000 Subject: [PATCH 153/158] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 6259d77..dcdfdb6 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,8 @@ }, "dependencies": { "@stdlib/types": "^0.4.3", - "@stdlib/utils-library-manifest": "^0.2.2" + "@stdlib/utils-library-manifest": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, "devDependencies": { "@stdlib/string-left-pad": "^0.2.2", @@ -84,4 +85,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From e554b58330b75d7d3393b8fd79c08a12bafbbcc3 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 30 Jun 2025 02:27:01 +0000 Subject: [PATCH 154/158] Remove files --- browser.js | 3 - browser.js.map | 1 - index.js | 3 - index.js.map | 1 - stats_browser.html | 4842 -------------------------------------------- stats_node.html | 4842 -------------------------------------------- 6 files changed, 9692 deletions(-) delete mode 100644 browser.js delete mode 100644 browser.js.map delete mode 100644 index.js delete mode 100644 index.js.map delete mode 100644 stats_browser.html delete mode 100644 stats_node.html diff --git a/browser.js b/browser.js deleted file mode 100644 index 14405dc..0000000 --- a/browser.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); -//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map deleted file mode 100644 index aa4b2bb..0000000 --- a/browser.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"browser.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/index.js b/index.js deleted file mode 100644 index 0e33446..0000000 --- a/index.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); -//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map deleted file mode 100644 index 0c02c0f..0000000 --- a/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/stats_browser.html b/stats_browser.html deleted file mode 100644 index 2f35700..0000000 --- a/stats_browser.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - diff --git a/stats_node.html b/stats_node.html deleted file mode 100644 index c264c7d..0000000 --- a/stats_node.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 472d1d3befc77e6b46fb231bded66d777c7a2b02 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 30 Jun 2025 02:27:15 +0000 Subject: [PATCH 155/158] Auto-generated commit --- .editorconfig | 180 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 194 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 257 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 178 +- SECURITY.md | 5 - benchmark/benchmark.js | 112 - benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 149 - branches.md | 56 - browser.js | 3 + browser.js.map | 1 + dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 39 - docs/types/index.d.ts | 177 - docs/types/test.ts | 45 - examples/c/Makefile | 146 - examples/c/example.c | 50 - examples/index.js | 54 - .../stdlib/ndarray/base/broadcast_shapes.h | 40 - index.js | 3 + index.js.map | 1 + lib/index.js | 45 - lib/main.js | 256 - manifest.json | 38 - package.json | 58 +- src/main.c | 118 - stats_browser.html | 4842 +++++++++++++++++ stats_node.html | 4842 +++++++++++++++++ test/dist/test.js | 33 - test/test.js | 230 - 54 files changed, 9729 insertions(+), 5494 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.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 branches.md create mode 100644 browser.js create mode 100644 browser.js.map 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/index.d.ts delete mode 100644 docs/types/test.ts delete mode 100644 examples/c/Makefile delete mode 100644 examples/c/example.c delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/broadcast_shapes.h create mode 100644 index.js create mode 100644 index.js.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 manifest.json delete mode 100644 src/main.c create mode 100644 stats_browser.html create mode 100644 stats_node.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 8dfab08..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2025-06-30T01:23:01.692Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index c8c532b..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 a07d970..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 7292af0..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: '0 12 * * 5' - - # 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 +``` -```javascript -var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); +If no recognized module system is present, access bundle contents via the global scope: + +```html + ``` #### broadcastShapes( shapes ) @@ -245,9 +251,14 @@ var sh = broadcastShapes( [ sh1, sh2 ] ); -```javascript -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); +```html + + + + + + + + ```
@@ -288,131 +304,7 @@ for ( i = 0; i < shapes.length; i++ ) { -* * * - -
- -## C APIs - - - -
- -
- - - - - -
- -### Usage - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -``` - -#### stdlib_ndarray_broadcast_shapes( M, \*\*shapes, \*ndims, \*out ) - -Broadcasts array shapes to a single shape. - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -int64_t N1 = 4; -int64_t sh1[] = { 8, 1, 6, 1 }; - -int64_t N2 = 3; -int64_t sh2[] = { 7, 1, 5 }; - -int64_t ndims[] = { N1, N2 }; -int64_t *shapes[] = { sh1, sh2 }; - -int64_t out[] = { 0, 0, 0, 0 }; -int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -if ( status != 0 ) { - // Handle error... -} -``` - -The function accepts the following arguments: - -- **M**: `[in] int64_t` number of shape arrays. -- **shapes**: `[in] int64_t**` array of shape arrays (dimensions). -- **ndims**: `[in] int64_t*` number of dimensions for each respective shape array. -- **out**: `[out] int64_t*` output shape array. - -```c -int8_t stdlib_ndarray_broadcast_shapes( const int64_t M, const int64_t *shapes[], const int64_t ndims[], int64_t *out ); -``` - -If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). - -
- - - - - -
- -### Notes - -- Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. - -
- - - - - -
- -### Examples - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main( void ) { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} -``` - -
- - - -
- 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.js b/benchmark/benchmark.js deleted file mode 100644 index 6426216..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,112 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pkg = require( './../package.json' ).name; -var broadcastShapes = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::two_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ] ], - [ [ 3, 2 ], [ 3, 1 ] ], - [ [ 1, 1 ], [ 2, 2 ] ], - [ [ 1 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::three_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::four_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ], [ 8, 1, 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ], [ 1, 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ], [ 1, 1, 2, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ], [ 1 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ], [ 5, 1, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/c/Makefile b/benchmark/c/Makefile deleted file mode 100644 index 5dc545c..0000000 --- a/benchmark/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := benchmark.out - - -# RULES # - -#/ -# Compiles C source files. -# -# @param {string} SOURCE_FILES - list of C source files -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lpthread -lblas`) -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [C_COMPILER] - C compiler -# @param {string} [CFLAGS] - C compiler flags -# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} SOURCE_FILES - list of C source files -# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {(string|void)} LIBRARIES - list of libraries (e.g., `-lpthread -lblas`) -# @param {(string|void)} LIBPATH - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} CC - C compiler -# @param {string} CFLAGS - C compiler flags -# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled benchmarks. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/benchmark/c/benchmark.c b/benchmark/c/benchmark.c deleted file mode 100644 index 82d2be5..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,149 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "broadcast-shapes" -#define ITERATIONS 1000000 -#define REPEATS 3 - -/** -* Prints the TAP version. -*/ -static void print_version( void ) { - printf( "TAP version 13\n" ); -} - -/** -* Prints the TAP summary. -* -* @param total total number of tests -* @param passing total number of passing tests -*/ -static void print_summary( int total, int passing ) { - printf( "#\n" ); - printf( "1..%d\n", total ); // TAP plan - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); -} - -/** -* Prints benchmarks results. -* -* @param elapsed elapsed time in seconds -*/ -static void print_results( double elapsed ) { - double rate = (double)ITERATIONS / elapsed; - printf( " ---\n" ); - printf( " iterations: %d\n", ITERATIONS ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", rate ); - printf( " ...\n" ); -} - -/** -* Returns a clock time. -* -* @return clock time -*/ -static double tic( void ) { - struct timeval now; - gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; -} - -/** -* Generates a random number on the interval [0,1). -* -* @return random number -*/ -static double rand_double( void ) { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark( void ) { - double elapsed; - int8_t status; - double t; - int i; - - const int64_t sh1[] = { 8, 1, 6, 1 }; - const int64_t sh2[] = { 7, 1, 5 }; - - const int64_t ndims[] = { 4, 3 }; - const int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( out[ 0 ] != 8 ) { - printf( "unexpected result\n" ); - } - if ( out[ 1 ] != 7 ) { - printf( "unexpected result\n" ); - } - if ( out[ 2 ] != 6 ) { - printf( "unexpected result\n" ); - } - if ( out[ 3 ] != 5 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Main execution sequence. -*/ -int main( void ) { - double elapsed; - int i; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - for ( i = 0; i < REPEATS; i++ ) { - printf( "# c::native::%s::two_arrays\n", NAME ); - elapsed = benchmark(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", i+1 ); - } - print_summary( REPEATS, REPEATS ); -} diff --git a/branches.md b/branches.md deleted file mode 100644 index 79909c9..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes" -%% click B href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/blob/esm/README.md \ No newline at end of file diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..14405dc --- /dev/null +++ b/browser.js @@ -0,0 +1,3 @@ +// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map new file mode 100644 index 0000000..aa4b2bb --- /dev/null +++ b/browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"browser.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 87ea8b6..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import broadcastShapes from '../docs/types/index'; -export = broadcastShapes; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 625741a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var d=function(t,e){return function(){return e||t((e={exports:{}}).exports,e),e.exports}};var h=d(function(x,c){ -function g(t){var e,n,u,o,s,l,a,f,i,r,v;if(f=t.length,n=[],f===0)return n;if(o=t[0],i=o.length,f===1){for(r=0;ri&&(i=e[r]);for(r=0;r=0;){for(s=e[0]-i+r,s>=0?u=o[s]:u=1,v=1;v=0?a=t[v][l]:a=1,u===1){u=a;continue}if(!(a===1||u===a))return null}n[r]=u,r-=1}return n}c.exports=g -});var m=h();module.exports=m; -/** @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 db2949f..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = broadcastShapes;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast array shapes to a single shape.\n*\n* @module @stdlib/ndarray-base-broadcast-shapes\n*\n* @example\n* var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' );\n*\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\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,cAkLA,SAASC,EAAiBC,EAAS,CAClC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GAFAH,EAAIR,EAAO,OACXE,EAAM,CAAC,EACFM,IAAM,EACV,OAAON,EAMR,GAJAE,EAAKJ,EAAQ,CAAE,EACfS,EAAIL,EAAG,OAGFI,IAAM,EAAI,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAI,KAAME,EAAIM,CAAE,CAAE,EAEnB,OAAOR,CACR,CAGA,IADAD,EAAQ,CAAEQ,CAAE,EACNC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAM,KAAMD,EAAQU,CAAE,EAAE,MAAO,EAC1BT,EAAOS,CAAE,EAAID,IACjBA,EAAIR,EAAOS,CAAE,GAIf,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAI,KAAM,CAAE,EAIb,IADAQ,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IANAL,EAAKJ,EAAO,CAAE,EAAIQ,EAAIC,EACjBL,GAAM,EACVF,EAAMC,EAAIC,CAAG,EAEbF,EAAM,EAEDQ,EAAI,EAAGA,EAAIH,EAAGG,IAAM,CAOzB,GANAL,EAAKL,EAAOU,CAAE,EAAIF,EAAIC,EACjBJ,GAAM,EACVC,EAAIP,EAAQW,CAAE,EAAGL,CAAG,EAEpBC,EAAI,EAEAJ,IAAQ,EAAI,CAChBA,EAAMI,EACN,QACD,CACA,GAAK,EAAAA,IAAM,GAAKJ,IAAQI,GAKxB,OAAO,IACR,CACAL,EAAKQ,CAAE,EAAIP,EACXO,GAAK,CACN,CACA,OAAOR,CACR,CAKAJ,EAAO,QAAUC,ICxNjB,IAAIa,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "broadcastShapes", "shapes", "ndims", "out", "dim", "sh", "n1", "n2", "d", "M", "N", "i", "j", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f1d92f6..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,39 +0,0 @@ - -{{alias}}( shapes ) - Broadcasts array shapes to a single shape. - - Two respective dimensions in two shape arrays are compatible if - - 1. the dimensions are equal. - 2. one dimension is `1`. - - The function returns `null` if provided incompatible shapes (i.e., shapes - which cannot be broadcast with one another). - - Parameters - ---------- - shapes: Array - Array of shape arrays. - - Returns - ------- - out: Array|null - Broadcast shape. - - Examples - -------- - // Compatible shapes: - > var sh1 = [ 8, 1, 6, 1 ]; - > var sh2 = [ 7, 1, 5 ]; - > var sh = {{alias}}( [ sh1, sh2 ] ) - [ 8, 7, 6, 5 ] - - // Incompatible shapes: - > sh1 = [ 3, 2 ]; - > sh1 = [ 2, 3 ]; - > sh = {{alias}}( [ sh1, sh2 ] ) - null - - See Also - -------- - diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts deleted file mode 100644 index c2702cf..0000000 --- a/docs/types/index.d.ts +++ /dev/null @@ -1,177 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ArrayLike } from '@stdlib/types/array'; - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param shapes - array shapes -* @returns broadcast shape -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -declare function broadcastShapes( shapes: ArrayLike> ): ArrayLike; - - -// EXPORTS // - -export = broadcastShapes; diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 2886539..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 broadcastShapes = require( './index' ); - - -// TESTS // - -// The function returns an array of numbers... -{ - broadcastShapes( [ [ 1, 2 ], [ 2, 2 ] ] ); // $ExpectType ArrayLike -} - -// The compiler throws an error if the function is not provided an array-like object containing array-like objects containing numbers... -{ - broadcastShapes( '5' ); // $ExpectError - broadcastShapes( 5 ); // $ExpectError - broadcastShapes( true ); // $ExpectError - broadcastShapes( false ); // $ExpectError - broadcastShapes( null ); // $ExpectError - broadcastShapes( {} ); // $ExpectError - broadcastShapes( [ '5' ] ); // $ExpectError - broadcastShapes( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - broadcastShapes(); // $ExpectError - broadcastShapes( [ [ 1, 2, 3 ] ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/c/Makefile b/examples/c/Makefile deleted file mode 100644 index 70c91f4..0000000 --- a/examples/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := example.out - - -# RULES # - -#/ -# Compiles source files. -# -# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) -# @param {string} [CFLAGS] - C compiler options -# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) -# @param {string} [SOURCE_FILES] - list of source files -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} CC - C compiler (e.g., `gcc`) -# @param {string} CFLAGS - C compiler options -# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) -# @param {string} SOURCE_FILES - list of source files -# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) -# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled examples. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/examples/c/example.c b/examples/c/example.c deleted file mode 100644 index 4bc54d5..0000000 --- a/examples/c/example.c +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main( void ) { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 28811f9..0000000 --- a/examples/index.js +++ /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. -*/ - -'use strict'; - -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( './../lib' ); - -var shapes; -var out; -var sh; -var i; -var j; - -function shape2string( shape ) { - return lpad( shape.join( ' x ' ), 20, ' ' ); -} - -shapes = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] -]; - -for ( i = 0; i < shapes.length; i++ ) { - sh = shapes[ i ]; - for ( j = 0; j < sh.length; j++ ) { - console.log( shape2string( sh[ j ] ) ); - } - console.log( lpad( '', 20, '-' ) ); - - out = broadcastShapes( sh ); - console.log( shape2string( out )+'\n' ); -} diff --git a/include/stdlib/ndarray/base/broadcast_shapes.h b/include/stdlib/ndarray/base/broadcast_shapes.h deleted file mode 100644 index 33581cb..0000000 --- a/include/stdlib/ndarray/base/broadcast_shapes.h +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#ifndef STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H -#define STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H - -#include - -/* -* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. -*/ -#ifdef __cplusplus -extern "C" { -#endif - -/** -* Broadcasts array shapes to a single shape. -*/ -int8_t stdlib_ndarray_broadcast_shapes( const int64_t M, const int64_t *shapes[], const int64_t ndims[], int64_t *out ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H diff --git a/index.js b/index.js new file mode 100644 index 0000000..0e33446 --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map new file mode 100644 index 0000000..0c02c0f --- /dev/null +++ b/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 0c9817e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Broadcast array shapes to a single shape. -* -* @module @stdlib/ndarray-base-broadcast-shapes -* -* @example -* var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); -* -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -*/ - -// 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 8558e60..0000000 --- a/lib/main.js +++ /dev/null @@ -1,256 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param {Array} shapes - array of shape arrays -* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`) -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [ 8, 0, 1, 6, 1 ], -* [ 8, 8, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -function broadcastShapes( shapes ) { - var ndims; - var out; - var dim; - var sh; - var n1; - var n2; - var d; - var M; - var N; - var i; - var j; - - M = shapes.length; - out = []; - if ( M === 0 ) { - return out; - } - sh = shapes[ 0 ]; - N = sh.length; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M === 1 ) { - // Need to manually copy to output shape, as shapes could be array-like objects... - for ( i = 0; i < N; i++ ) { - out.push( sh[ i ] ); - } - return out; - } - // Determine the maximum dimensionality... - ndims = [ N ]; - for ( i = 1; i < M; i++ ) { - ndims.push( shapes[ i ].length ); - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Initialize the output array... - for ( i = 0; i < N; i++ ) { - out.push( 0 ); - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim === 1 ) { - dim = d; - continue; - } - if ( d === 1 || dim === d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return null; - } - out[ i ] = dim; - i -= 1; - } - return out; -} - - -// EXPORTS // - -module.exports = broadcastShapes; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 04e61e3..0000000 --- a/manifest.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "options": {}, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [] - } - ] -} diff --git a/package.json b/package.json index dcdfdb6..a9ff889 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,7 @@ "version": "0.2.2", "description": "Broadcast array shapes to a single shape.", "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", - "include": "./include", - "lib": "./lib", - "src": "./src", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "main": "./index.js", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,33 +12,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/types": "^0.4.3", - "@stdlib/utils-library-manifest": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/string-left-pad": "^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", "stdtypes", @@ -80,9 +27,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 547d921..0000000 --- a/src/main.c +++ /dev/null @@ -1,118 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). -* -* - Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. -* -* @param M number of array shapes -* @param shapes pointer to an array containing shape arrays -* @param ndims array containing the number of dimensions for (i.e., length of) each respective shape array -* @param out pointer to output array -* @return status -* -* @example -* #include "stdlib/ndarray/base/broadcast_shapes.h" -* #include -* -* int64_t N1 = 4; -* int64_t sh1[] = { 8, 1, 6, 1 }; -* -* int64_t N2 = 3; -* int64_t sh2[] = { 7, 1, 5 }; -* -* int64_t ndims[] = { N1, N2 }; -* int64_t *shapes[] = { sh1, sh2 }; -* -* int64_t out[] = { 0, 0, 0, 0 }; -* int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -*/ -int8_t stdlib_ndarray_broadcast_shapes( const int64_t M, const int64_t *shapes[], const int64_t ndims[], int64_t *out ) { - int64_t dim; - const int64_t *sh; - int64_t n1; - int64_t n2; - int64_t d; - int64_t N; - int64_t i; - int64_t j; - - if ( M == 0 ) { - return 0; - } - sh = shapes[ 0 ]; - N = ndims[ 0 ]; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M == 1 ) { - for ( i = 0; i < N; i++ ) { - out[ i ] = sh[ i ]; - } - return 0; - } - // Determine the maximum dimensionality... - for ( i = 1; i < M; i++ ) { - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim == 1 ) { - dim = d; - continue; - } - if ( d == 1 || dim == d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return -1; - } - out[ i ] = dim; - i -= 1; - } - return 0; -} diff --git a/stats_browser.html b/stats_browser.html new file mode 100644 index 0000000..2f35700 --- /dev/null +++ b/stats_browser.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/stats_node.html b/stats_node.html new file mode 100644 index 0000000..c264c7d --- /dev/null +++ b/stats_node.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 63f703c..0000000 --- a/test/test.js +++ /dev/null @@ -1,230 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var broadcastShapes = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastShapes, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] - ]; - - expected = [ - [ 1, 2 ], - [ 3, 4 ], - [ 5, 6, 7 ], - [ 3, 3 ], - [ 3 ], - [ 3, 2 ], - [ 2, 3 ], - [ 1, 2 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty dims)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 0 ], [ 0, 0 ] ], - [ [ 0, 1 ], [ 0, 0 ] ], - [ [ 1, 0 ], [ 0, 1 ] ], - [ [ 1, 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 1, 0 ] ], - [ [ 1, 1 ], [ 0, 1 ] ], - [ [ 0 ], [ 0, 0 ] ], - [ [ 0 ], [ 0, 1 ] ], - [ [ 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 0 ] ], - [ [ 1 ], [ 0, 1 ] ], - [ [ 1 ], [ 1, 0 ] ], - [ [ 1 ], [ 8, 0 ] ], - [ [ 8, 1, 6, 1 ], [ 0, 1, 5 ] ], - [ [ 8, 0, 6, 1 ], [ 1, 5 ] ] - ]; - - expected = [ - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 1, 0 ], - [ 8, 0 ], - [ 8, 0, 6, 5 ], - [ 8, 0, 6, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (no shapes)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [] - ]; - - expected = [ - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty shapes (i.e., zero-dimensional array broadcasting))', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [] ], - [ [], [] ], - [ [], [], [] ], - [ [], [ 0 ] ], - [ [ 0 ], [] ], - [ [], [ 0, 0 ] ], - [ [ 0, 0 ], [] ], - [ [], [ 1, 0 ] ], - [ [], [ 0, 1 ] ], - [ [], [ 3, 3 ] ], - [ [], [ 3, 3 ], [] ] - ]; - - expected = [ - [], - [], - [], - [ 0 ], - [ 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 3, 3 ], - [ 3, 3 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (single shape)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 7 ] ], - [ [ 1, 1 ] ], - [ [ 5, 6, 1 ] ] - ]; - - expected = [ - [ 7 ], - [ 1, 1 ], - [ 5, 6, 1 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function returns `null` if provided incompatible shapes', function test( t ) { - var actual; - var values; - var i; - - values = [ - [ [ 3 ], [ 4 ] ], - [ [ 2, 3 ], [ 2 ] ], - [ [ 3 ], [ 3 ], [ 4 ] ], - [ [ 1, 3, 4 ], [ 2, 3, 3 ] ], - [ [ 1, 2 ], [ 3, 1 ], [ 3, 2 ], [ 10, 5 ] ], - [ [ 2 ], [ 2, 3 ] ], - [ [ 2 ], [ 2 ], [ 2 ], [ 2 ], [ 3 ], [ 3 ], [ 3 ], [ 3 ] ], - [ [ 9, 0, 9 ], [ 0, 9, 0 ] ], - [ [ 9, 9, 9 ], [ 0, 9, 9 ] ], - [ [ 9, 0, 9 ], [ 9, 9, 9 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 0 ] ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.strictEqual( actual, null, 'returns expected value. i: '+i+'.' ); - } - t.end(); -}); From 7e340bb9169719f8cbce72cfe5cf0e139d2c84ca Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 18 Aug 2025 01:12:05 +0000 Subject: [PATCH 156/158] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 6259d77..dcdfdb6 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,8 @@ }, "dependencies": { "@stdlib/types": "^0.4.3", - "@stdlib/utils-library-manifest": "^0.2.2" + "@stdlib/utils-library-manifest": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, "devDependencies": { "@stdlib/string-left-pad": "^0.2.2", @@ -84,4 +85,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From be31c549fa76dfc389e767c1850cc0d86b834616 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 18 Aug 2025 01:14:04 +0000 Subject: [PATCH 157/158] Remove files --- browser.js | 3 - browser.js.map | 1 - index.js | 3 - index.js.map | 1 - stats_browser.html | 4842 -------------------------------------------- stats_node.html | 4842 -------------------------------------------- 6 files changed, 9692 deletions(-) delete mode 100644 browser.js delete mode 100644 browser.js.map delete mode 100644 index.js delete mode 100644 index.js.map delete mode 100644 stats_browser.html delete mode 100644 stats_node.html diff --git a/browser.js b/browser.js deleted file mode 100644 index 14405dc..0000000 --- a/browser.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); -//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map deleted file mode 100644 index aa4b2bb..0000000 --- a/browser.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"browser.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/index.js b/index.js deleted file mode 100644 index 0e33446..0000000 --- a/index.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); -//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map deleted file mode 100644 index 0c02c0f..0000000 --- a/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/stats_browser.html b/stats_browser.html deleted file mode 100644 index 2f35700..0000000 --- a/stats_browser.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - diff --git a/stats_node.html b/stats_node.html deleted file mode 100644 index c264c7d..0000000 --- a/stats_node.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 18593245860f007629eae207b8289f0118088f09 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 18 Aug 2025 01:14:36 +0000 Subject: [PATCH 158/158] Auto-generated commit --- .editorconfig | 180 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 194 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 257 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 178 +- SECURITY.md | 5 - benchmark/benchmark.js | 112 - benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 149 - branches.md | 56 - browser.js | 3 + browser.js.map | 1 + dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 39 - docs/types/index.d.ts | 177 - docs/types/test.ts | 45 - examples/c/Makefile | 146 - examples/c/example.c | 50 - examples/index.js | 54 - .../stdlib/ndarray/base/broadcast_shapes.h | 40 - index.js | 3 + index.js.map | 1 + lib/index.js | 45 - lib/main.js | 256 - manifest.json | 38 - package.json | 58 +- src/main.c | 118 - stats_browser.html | 4842 +++++++++++++++++ stats_node.html | 4842 +++++++++++++++++ test/dist/test.js | 33 - test/test.js | 230 - 54 files changed, 9729 insertions(+), 5494 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.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 branches.md create mode 100644 browser.js create mode 100644 browser.js.map 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/index.d.ts delete mode 100644 docs/types/test.ts delete mode 100644 examples/c/Makefile delete mode 100644 examples/c/example.c delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/broadcast_shapes.h create mode 100644 index.js create mode 100644 index.js.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 manifest.json delete mode 100644 src/main.c create mode 100644 stats_browser.html create mode 100644 stats_node.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 6a11ba9..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2025-08-18T01:07:16.101Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index c8c532b..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 a07d970..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes) 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 7292af0..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: '0 12 * * 5' - - # 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 +``` -```javascript -var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); +If no recognized module system is present, access bundle contents via the global scope: + +```html + ``` #### broadcastShapes( shapes ) @@ -245,9 +251,14 @@ var sh = broadcastShapes( [ sh1, sh2 ] ); -```javascript -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); +```html + + + + + + + + ```
@@ -288,131 +304,7 @@ for ( i = 0; i < shapes.length; i++ ) { -* * * - -
- -## C APIs - - - -
- -
- - - - - -
- -### Usage - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -``` - -#### stdlib_ndarray_broadcast_shapes( M, \*\*shapes, \*ndims, \*out ) - -Broadcasts array shapes to a single shape. - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -int64_t N1 = 4; -int64_t sh1[] = { 8, 1, 6, 1 }; - -int64_t N2 = 3; -int64_t sh2[] = { 7, 1, 5 }; - -int64_t ndims[] = { N1, N2 }; -int64_t *shapes[] = { sh1, sh2 }; - -int64_t out[] = { 0, 0, 0, 0 }; -int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -if ( status != 0 ) { - // Handle error... -} -``` - -The function accepts the following arguments: - -- **M**: `[in] int64_t` number of shape arrays. -- **shapes**: `[in] int64_t**` array of shape arrays (dimensions). -- **ndims**: `[in] int64_t*` number of dimensions for each respective shape array. -- **out**: `[out] int64_t*` output shape array. - -```c -int8_t stdlib_ndarray_broadcast_shapes( const int64_t M, const int64_t *shapes[], const int64_t ndims[], int64_t *out ); -``` - -If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). - -
- - - - - -
- -### Notes - -- Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. - -
- - - - - -
- -### Examples - -```c -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main( void ) { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} -``` - -
- - - -
- 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.js b/benchmark/benchmark.js deleted file mode 100644 index 6426216..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,112 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pkg = require( './../package.json' ).name; -var broadcastShapes = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::two_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ] ], - [ [ 3, 2 ], [ 3, 1 ] ], - [ [ 1, 1 ], [ 2, 2 ] ], - [ [ 1 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::three_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::four_shapes', function benchmark( b ) { - var values; - var out; - var i; - - values = [ - [ [ 8, 1, 6, 1 ], [ 7, 1, 5 ], [ 1, 1 ], [ 8, 1, 1, 1 ] ], - [ [ 3, 2 ], [ 3, 1 ], [ 3, 2 ], [ 1, 3, 2 ] ], - [ [ 1, 1 ], [ 2, 2 ], [ 2, 1, 2 ], [ 1, 1, 2, 2 ] ], - [ [ 1 ], [ 7 ], [ 7 ], [ 1 ] ], - [ [ 1, 1, 1, 1, 1 ], [ 5, 5, 5, 5, 5 ], [ 5 ], [ 5, 1, 5 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = broadcastShapes( values[ i%values.length ] ); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - } - b.toc(); - if ( out === null || out[ out.length-1 ] !== out[ out.length-1 ] ) { - b.fail( 'something went wrong' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/c/Makefile b/benchmark/c/Makefile deleted file mode 100644 index 5dc545c..0000000 --- a/benchmark/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := benchmark.out - - -# RULES # - -#/ -# Compiles C source files. -# -# @param {string} SOURCE_FILES - list of C source files -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lpthread -lblas`) -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [C_COMPILER] - C compiler -# @param {string} [CFLAGS] - C compiler flags -# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} SOURCE_FILES - list of C source files -# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {(string|void)} LIBRARIES - list of libraries (e.g., `-lpthread -lblas`) -# @param {(string|void)} LIBPATH - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} CC - C compiler -# @param {string} CFLAGS - C compiler flags -# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled benchmarks. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/benchmark/c/benchmark.c b/benchmark/c/benchmark.c deleted file mode 100644 index 82d2be5..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,149 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "broadcast-shapes" -#define ITERATIONS 1000000 -#define REPEATS 3 - -/** -* Prints the TAP version. -*/ -static void print_version( void ) { - printf( "TAP version 13\n" ); -} - -/** -* Prints the TAP summary. -* -* @param total total number of tests -* @param passing total number of passing tests -*/ -static void print_summary( int total, int passing ) { - printf( "#\n" ); - printf( "1..%d\n", total ); // TAP plan - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); -} - -/** -* Prints benchmarks results. -* -* @param elapsed elapsed time in seconds -*/ -static void print_results( double elapsed ) { - double rate = (double)ITERATIONS / elapsed; - printf( " ---\n" ); - printf( " iterations: %d\n", ITERATIONS ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", rate ); - printf( " ...\n" ); -} - -/** -* Returns a clock time. -* -* @return clock time -*/ -static double tic( void ) { - struct timeval now; - gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; -} - -/** -* Generates a random number on the interval [0,1). -* -* @return random number -*/ -static double rand_double( void ) { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark( void ) { - double elapsed; - int8_t status; - double t; - int i; - - const int64_t sh1[] = { 8, 1, 6, 1 }; - const int64_t sh2[] = { 7, 1, 5 }; - - const int64_t ndims[] = { 4, 3 }; - const int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( out[ 0 ] != 8 ) { - printf( "unexpected result\n" ); - } - if ( out[ 1 ] != 7 ) { - printf( "unexpected result\n" ); - } - if ( out[ 2 ] != 6 ) { - printf( "unexpected result\n" ); - } - if ( out[ 3 ] != 5 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Main execution sequence. -*/ -int main( void ) { - double elapsed; - int i; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - for ( i = 0; i < REPEATS; i++ ) { - printf( "# c::native::%s::two_arrays\n", NAME ); - elapsed = benchmark(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", i+1 ); - } - print_summary( REPEATS, REPEATS ); -} diff --git a/branches.md b/branches.md deleted file mode 100644 index 79909c9..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes" -%% click B href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/blob/esm/README.md \ No newline at end of file diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..14405dc --- /dev/null +++ b/browser.js @@ -0,0 +1,3 @@ +// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map new file mode 100644 index 0000000..aa4b2bb --- /dev/null +++ b/browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"browser.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 87ea8b6..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import broadcastShapes from '../docs/types/index'; -export = broadcastShapes; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 625741a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var d=function(t,e){return function(){return e||t((e={exports:{}}).exports,e),e.exports}};var h=d(function(x,c){ -function g(t){var e,n,u,o,s,l,a,f,i,r,v;if(f=t.length,n=[],f===0)return n;if(o=t[0],i=o.length,f===1){for(r=0;ri&&(i=e[r]);for(r=0;r=0;){for(s=e[0]-i+r,s>=0?u=o[s]:u=1,v=1;v=0?a=t[v][l]:a=1,u===1){u=a;continue}if(!(a===1||u===a))return null}n[r]=u,r-=1}return n}c.exports=g -});var m=h();module.exports=m; -/** @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 db2949f..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = broadcastShapes;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast array shapes to a single shape.\n*\n* @module @stdlib/ndarray-base-broadcast-shapes\n*\n* @example\n* var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' );\n*\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\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,cAkLA,SAASC,EAAiBC,EAAS,CAClC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GAFAH,EAAIR,EAAO,OACXE,EAAM,CAAC,EACFM,IAAM,EACV,OAAON,EAMR,GAJAE,EAAKJ,EAAQ,CAAE,EACfS,EAAIL,EAAG,OAGFI,IAAM,EAAI,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAI,KAAME,EAAIM,CAAE,CAAE,EAEnB,OAAOR,CACR,CAGA,IADAD,EAAQ,CAAEQ,CAAE,EACNC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAM,KAAMD,EAAQU,CAAE,EAAE,MAAO,EAC1BT,EAAOS,CAAE,EAAID,IACjBA,EAAIR,EAAOS,CAAE,GAIf,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAI,KAAM,CAAE,EAIb,IADAQ,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IANAL,EAAKJ,EAAO,CAAE,EAAIQ,EAAIC,EACjBL,GAAM,EACVF,EAAMC,EAAIC,CAAG,EAEbF,EAAM,EAEDQ,EAAI,EAAGA,EAAIH,EAAGG,IAAM,CAOzB,GANAL,EAAKL,EAAOU,CAAE,EAAIF,EAAIC,EACjBJ,GAAM,EACVC,EAAIP,EAAQW,CAAE,EAAGL,CAAG,EAEpBC,EAAI,EAEAJ,IAAQ,EAAI,CAChBA,EAAMI,EACN,QACD,CACA,GAAK,EAAAA,IAAM,GAAKJ,IAAQI,GAKxB,OAAO,IACR,CACAL,EAAKQ,CAAE,EAAIP,EACXO,GAAK,CACN,CACA,OAAOR,CACR,CAKAJ,EAAO,QAAUC,ICxNjB,IAAIa,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "broadcastShapes", "shapes", "ndims", "out", "dim", "sh", "n1", "n2", "d", "M", "N", "i", "j", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f1d92f6..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,39 +0,0 @@ - -{{alias}}( shapes ) - Broadcasts array shapes to a single shape. - - Two respective dimensions in two shape arrays are compatible if - - 1. the dimensions are equal. - 2. one dimension is `1`. - - The function returns `null` if provided incompatible shapes (i.e., shapes - which cannot be broadcast with one another). - - Parameters - ---------- - shapes: Array - Array of shape arrays. - - Returns - ------- - out: Array|null - Broadcast shape. - - Examples - -------- - // Compatible shapes: - > var sh1 = [ 8, 1, 6, 1 ]; - > var sh2 = [ 7, 1, 5 ]; - > var sh = {{alias}}( [ sh1, sh2 ] ) - [ 8, 7, 6, 5 ] - - // Incompatible shapes: - > sh1 = [ 3, 2 ]; - > sh1 = [ 2, 3 ]; - > sh = {{alias}}( [ sh1, sh2 ] ) - null - - See Also - -------- - diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts deleted file mode 100644 index c2702cf..0000000 --- a/docs/types/index.d.ts +++ /dev/null @@ -1,177 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ArrayLike } from '@stdlib/types/array'; - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param shapes - array shapes -* @returns broadcast shape -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -declare function broadcastShapes( shapes: ArrayLike> ): ArrayLike; - - -// EXPORTS // - -export = broadcastShapes; diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 2886539..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 broadcastShapes = require( './index' ); - - -// TESTS // - -// The function returns an array of numbers... -{ - broadcastShapes( [ [ 1, 2 ], [ 2, 2 ] ] ); // $ExpectType ArrayLike -} - -// The compiler throws an error if the function is not provided an array-like object containing array-like objects containing numbers... -{ - broadcastShapes( '5' ); // $ExpectError - broadcastShapes( 5 ); // $ExpectError - broadcastShapes( true ); // $ExpectError - broadcastShapes( false ); // $ExpectError - broadcastShapes( null ); // $ExpectError - broadcastShapes( {} ); // $ExpectError - broadcastShapes( [ '5' ] ); // $ExpectError - broadcastShapes( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - broadcastShapes(); // $ExpectError - broadcastShapes( [ [ 1, 2, 3 ] ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/c/Makefile b/examples/c/Makefile deleted file mode 100644 index 70c91f4..0000000 --- a/examples/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := example.out - - -# RULES # - -#/ -# Compiles source files. -# -# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) -# @param {string} [CFLAGS] - C compiler options -# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) -# @param {string} [SOURCE_FILES] - list of source files -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} CC - C compiler (e.g., `gcc`) -# @param {string} CFLAGS - C compiler options -# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) -# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) -# @param {string} SOURCE_FILES - list of source files -# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) -# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled examples. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/examples/c/example.c b/examples/c/example.c deleted file mode 100644 index 4bc54d5..0000000 --- a/examples/c/example.c +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include -#include -#include - -int main( void ) { - int64_t N1 = 4; - int64_t sh1[] = { 8, 1, 6, 1 }; - - int64_t N2 = 3; - int64_t sh2[] = { 7, 1, 5 }; - - int64_t ndims[] = { N1, N2 }; - int64_t *shapes[] = { sh1, sh2 }; - - int64_t out[] = { 0, 0, 0, 0 }; - int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); - if ( status != 0 ) { - printf( "incompatible shapes\n" ); - return 1; - } - int64_t i; - printf( "shape = ( " ); - for ( i = 0; i < N1; i++ ) { - printf( "%"PRId64"", out[ i ] ); - if ( i < N1-1 ) { - printf( ", " ); - } - } - printf( " )\n" ); - return 0; -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 28811f9..0000000 --- a/examples/index.js +++ /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. -*/ - -'use strict'; - -var lpad = require( '@stdlib/string-left-pad' ); -var broadcastShapes = require( './../lib' ); - -var shapes; -var out; -var sh; -var i; -var j; - -function shape2string( shape ) { - return lpad( shape.join( ' x ' ), 20, ' ' ); -} - -shapes = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] -]; - -for ( i = 0; i < shapes.length; i++ ) { - sh = shapes[ i ]; - for ( j = 0; j < sh.length; j++ ) { - console.log( shape2string( sh[ j ] ) ); - } - console.log( lpad( '', 20, '-' ) ); - - out = broadcastShapes( sh ); - console.log( shape2string( out )+'\n' ); -} diff --git a/include/stdlib/ndarray/base/broadcast_shapes.h b/include/stdlib/ndarray/base/broadcast_shapes.h deleted file mode 100644 index 33581cb..0000000 --- a/include/stdlib/ndarray/base/broadcast_shapes.h +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#ifndef STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H -#define STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H - -#include - -/* -* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. -*/ -#ifdef __cplusplus -extern "C" { -#endif - -/** -* Broadcasts array shapes to a single shape. -*/ -int8_t stdlib_ndarray_broadcast_shapes( const int64_t M, const int64_t *shapes[], const int64_t ndims[], int64_t *out ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_BROADCAST_SHAPES_H diff --git a/index.js b/index.js new file mode 100644 index 0000000..0e33446 --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,f;e=this,f=function(){"use strict";return function(e){var f,n,t,r,o,u,i,s,l,d,h;if(n=[],0===(s=e.length))return n;if(l=(r=e[0]).length,1===s){for(d=0;dl&&(l=f[d]);for(d=0;d=0;){for(t=(o=f[0]-l+d)>=0?r[o]:1,h=1;h=0?e[h][u]:1,1!==t){if(1!==i&&t!==i)return null}else t=i;n[d]=t,d-=1}return n}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define(f):(e="undefined"!=typeof globalThis?globalThis:e||self).broadcastShapes=f(); +//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map new file mode 100644 index 0000000..0c02c0f --- /dev/null +++ b/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Broadcasts array shapes to a single shape.\n*\n* ## Notes\n*\n* - Two respective dimensions in two shape arrays are compatible if\n*\n* 1. the dimensions are equal.\n* 2. one dimension is `1`.\n*\n* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another).\n*\n* @param {Array} shapes - array of shape arrays\n* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`)\n*\n* @example\n* var shapes = [\n* [ 8, 1, 6, 1 ],\n* [ 7, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 5, 4 ],\n* [ 4 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 5, 4 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 15, 1, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 15, 3, 5 ],\n* [ 3, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 15, 3, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 1, 7, 1, 5 ],\n* [ 8, 4, 1, 6, 5 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 4, 7, 6, 5 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 0 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 1, 1, 6, 0 ]\n*\n* @example\n* var shapes = [\n* [ 8, 1, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 8, 0, 1, 6, 1 ]\n*\n* @example\n* var shapes = [\n* [ 8, 8, 1, 6, 1 ],\n* [ 8, 0, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* [ 8, 0, 1, 6, 1 ],\n* [ 8, 8, 1, 6, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns null\n*\n* @example\n* var shapes = [\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [];\n*\n* var out = broadcastShapes( shapes );\n* // returns []\n*\n* @example\n* var shapes = [\n* [ 3, 2, 1 ],\n* []\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*\n* @example\n* var shapes = [\n* [],\n* [ 3, 2, 1 ]\n* ];\n*\n* var out = broadcastShapes( shapes );\n* // returns [ 3, 2, 1 ]\n*/\nfunction broadcastShapes( shapes ) {\n\tvar ndims;\n\tvar out;\n\tvar dim;\n\tvar sh;\n\tvar n1;\n\tvar n2;\n\tvar d;\n\tvar M;\n\tvar N;\n\tvar i;\n\tvar j;\n\n\tM = shapes.length;\n\tout = [];\n\tif ( M === 0 ) {\n\t\treturn out;\n\t}\n\tsh = shapes[ 0 ];\n\tN = sh.length;\n\n\t// If provided a single input shape array, then the broadcast shape is input shape...\n\tif ( M === 1 ) {\n\t\t// Need to manually copy to output shape, as shapes could be array-like objects...\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tout.push( sh[ i ] );\n\t\t}\n\t\treturn out;\n\t}\n\t// Determine the maximum dimensionality...\n\tndims = [ N ];\n\tfor ( i = 1; i < M; i++ ) {\n\t\tndims.push( shapes[ i ].length );\n\t\tif ( ndims[ i ] > N ) {\n\t\t\tN = ndims[ i ];\n\t\t}\n\t}\n\t// Initialize the output array...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tout.push( 0 );\n\t}\n\t// Compute the broadcast shape...\n\ti = N - 1;\n\twhile ( i >= 0 ) {\n\t\tn1 = ndims[ 0 ] - N + i;\n\t\tif ( n1 >= 0 ) {\n\t\t\tdim = sh[ n1 ];\n\t\t} else {\n\t\t\tdim = 1;\n\t\t}\n\t\tfor ( j = 1; j < M; j++ ) {\n\t\t\tn2 = ndims[ j ] - N + i;\n\t\t\tif ( n2 >= 0 ) {\n\t\t\t\td = shapes[ j ][ n2 ];\n\t\t\t} else {\n\t\t\t\td = 1;\n\t\t\t}\n\t\t\tif ( dim === 1 ) {\n\t\t\t\tdim = d;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ( d === 1 || dim === d ) {\n\t\t\t\t// When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same...\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// The current shape cannot be broadcast against one of the other shapes...\n\t\t\treturn null;\n\t\t}\n\t\tout[ i ] = dim;\n\t\ti -= 1;\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default broadcastShapes;\n"],"names":["shapes","ndims","out","dim","sh","n1","n2","d","M","N","i","j","length","push"],"mappings":";gDAkLA,SAA0BA,GACzB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAIJ,GADAT,EAAM,GACK,KAFXM,EAAIR,EAAOY,QAGV,OAAOV,EAMR,GAHAO,GADAL,EAAKJ,EAAQ,IACNY,OAGI,IAANJ,EAAU,CAEd,IAAME,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAMT,EAAIM,IAEf,OAAOR,CACP,CAGD,IADAD,EAAQ,CAAEQ,GACJC,EAAI,EAAGA,EAAIF,EAAGE,IACnBT,EAAMY,KAAMb,EAAQU,GAAIE,QACnBX,EAAOS,GAAMD,IACjBA,EAAIR,EAAOS,IAIb,IAAMA,EAAI,EAAGA,EAAID,EAAGC,IACnBR,EAAIW,KAAM,GAIX,IADAH,EAAID,EAAI,EACAC,GAAK,GAAI,CAOhB,IAJCP,GAFDE,EAAKJ,EAAO,GAAMQ,EAAIC,IACX,EACJN,EAAIC,GAEJ,EAEDM,EAAI,EAAGA,EAAIH,EAAGG,IAOnB,GAJCJ,GAFDD,EAAKL,EAAOU,GAAMF,EAAIC,IACX,EACNV,EAAQW,GAAKL,GAEb,EAEQ,IAARH,GAIL,GAAW,IAANI,GAAWJ,IAAQI,EAKxB,OAAO,UARNJ,EAAMI,EAURL,EAAKQ,GAAMP,EACXO,GAAK,CACL,CACD,OAAOR,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 0c9817e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Broadcast array shapes to a single shape. -* -* @module @stdlib/ndarray-base-broadcast-shapes -* -* @example -* var broadcastShapes = require( '@stdlib/ndarray-base-broadcast-shapes' ); -* -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -*/ - -// 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 8558e60..0000000 --- a/lib/main.js +++ /dev/null @@ -1,256 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 // - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - The function returns `null` if provided incompatible shapes (i.e., shapes which cannot be broadcast with one another). -* -* @param {Array} shapes - array of shape arrays -* @returns {(NonNegativeIntegerArray|null)} broadcast shape (or `null`) -* -* @example -* var shapes = [ -* [ 8, 1, 6, 1 ], -* [ 7, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 5, 4 ], -* [ 4 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 5, 4 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 15, 1, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 15, 3, 5 ], -* [ 3, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 15, 3, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 1, 7, 1, 5 ], -* [ 8, 4, 1, 6, 5 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 4, 7, 6, 5 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 0 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 1, 1, 6, 0 ] -* -* @example -* var shapes = [ -* [ 8, 1, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 8, 0, 1, 6, 1 ] -* -* @example -* var shapes = [ -* [ 8, 8, 1, 6, 1 ], -* [ 8, 0, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [ 8, 0, 1, 6, 1 ], -* [ 8, 8, 1, 6, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns null -* -* @example -* var shapes = [ -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = []; -* -* var out = broadcastShapes( shapes ); -* // returns [] -* -* @example -* var shapes = [ -* [ 3, 2, 1 ], -* [] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -* -* @example -* var shapes = [ -* [], -* [ 3, 2, 1 ] -* ]; -* -* var out = broadcastShapes( shapes ); -* // returns [ 3, 2, 1 ] -*/ -function broadcastShapes( shapes ) { - var ndims; - var out; - var dim; - var sh; - var n1; - var n2; - var d; - var M; - var N; - var i; - var j; - - M = shapes.length; - out = []; - if ( M === 0 ) { - return out; - } - sh = shapes[ 0 ]; - N = sh.length; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M === 1 ) { - // Need to manually copy to output shape, as shapes could be array-like objects... - for ( i = 0; i < N; i++ ) { - out.push( sh[ i ] ); - } - return out; - } - // Determine the maximum dimensionality... - ndims = [ N ]; - for ( i = 1; i < M; i++ ) { - ndims.push( shapes[ i ].length ); - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Initialize the output array... - for ( i = 0; i < N; i++ ) { - out.push( 0 ); - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim === 1 ) { - dim = d; - continue; - } - if ( d === 1 || dim === d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return null; - } - out[ i ] = dim; - i -= 1; - } - return out; -} - - -// EXPORTS // - -module.exports = broadcastShapes; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 04e61e3..0000000 --- a/manifest.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "options": {}, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [] - } - ] -} diff --git a/package.json b/package.json index dcdfdb6..a9ff889 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,7 @@ "version": "0.2.2", "description": "Broadcast array shapes to a single shape.", "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", - "include": "./include", - "lib": "./lib", - "src": "./src", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "main": "./index.js", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,33 +12,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/types": "^0.4.3", - "@stdlib/utils-library-manifest": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/string-left-pad": "^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", "stdtypes", @@ -80,9 +27,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 547d921..0000000 --- a/src/main.c +++ /dev/null @@ -1,118 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/ndarray/base/broadcast_shapes.h" -#include - -/** -* Broadcasts array shapes to a single shape. -* -* ## Notes -* -* - Two respective dimensions in two shape arrays are compatible if -* -* 1. the dimensions are equal. -* 2. one dimension is `1`. -* -* - If successful, the function returns `0`; otherwise, the function returns `-1` (e.g., due to incompatible shapes). -* -* - Even if the function is unsuccessful, the function may still overwrite elements in the output array before returning. In other words, do not assume that providing incompatible shapes is a no-op with regard to the output array. -* -* @param M number of array shapes -* @param shapes pointer to an array containing shape arrays -* @param ndims array containing the number of dimensions for (i.e., length of) each respective shape array -* @param out pointer to output array -* @return status -* -* @example -* #include "stdlib/ndarray/base/broadcast_shapes.h" -* #include -* -* int64_t N1 = 4; -* int64_t sh1[] = { 8, 1, 6, 1 }; -* -* int64_t N2 = 3; -* int64_t sh2[] = { 7, 1, 5 }; -* -* int64_t ndims[] = { N1, N2 }; -* int64_t *shapes[] = { sh1, sh2 }; -* -* int64_t out[] = { 0, 0, 0, 0 }; -* int8_t status = stdlib_ndarray_broadcast_shapes( 2, shapes, ndims, out ); -*/ -int8_t stdlib_ndarray_broadcast_shapes( const int64_t M, const int64_t *shapes[], const int64_t ndims[], int64_t *out ) { - int64_t dim; - const int64_t *sh; - int64_t n1; - int64_t n2; - int64_t d; - int64_t N; - int64_t i; - int64_t j; - - if ( M == 0 ) { - return 0; - } - sh = shapes[ 0 ]; - N = ndims[ 0 ]; - - // If provided a single input shape array, then the broadcast shape is input shape... - if ( M == 1 ) { - for ( i = 0; i < N; i++ ) { - out[ i ] = sh[ i ]; - } - return 0; - } - // Determine the maximum dimensionality... - for ( i = 1; i < M; i++ ) { - if ( ndims[ i ] > N ) { - N = ndims[ i ]; - } - } - // Compute the broadcast shape... - i = N - 1; - while ( i >= 0 ) { - n1 = ndims[ 0 ] - N + i; - if ( n1 >= 0 ) { - dim = sh[ n1 ]; - } else { - dim = 1; - } - for ( j = 1; j < M; j++ ) { - n2 = ndims[ j ] - N + i; - if ( n2 >= 0 ) { - d = shapes[ j ][ n2 ]; - } else { - d = 1; - } - if ( dim == 1 ) { - dim = d; - continue; - } - if ( d == 1 || dim == d ) { - // When either `d` is `1` or `d` equals the current output shape dimension, the current output shape dimension remains the same... - continue; - } - // The current shape cannot be broadcast against one of the other shapes... - return -1; - } - out[ i ] = dim; - i -= 1; - } - return 0; -} diff --git a/stats_browser.html b/stats_browser.html new file mode 100644 index 0000000..2f35700 --- /dev/null +++ b/stats_browser.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/stats_node.html b/stats_node.html new file mode 100644 index 0000000..c264c7d --- /dev/null +++ b/stats_node.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 63f703c..0000000 --- a/test/test.js +++ /dev/null @@ -1,230 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var broadcastShapes = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastShapes, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 2 ], [ 2 ] ], - [ [ 1, 1 ], [ 3, 4 ] ], - [ [ 6, 7 ], [ 5, 6, 1 ], [ 7 ], [ 5, 1, 7 ] ], - [ [ 1, 3 ], [ 3, 1 ] ], - [ [ 1 ], [ 3 ] ], - [ [ 2 ], [ 3, 2 ] ], - [ [ 2, 3 ], [ 2, 3 ], [ 2, 3 ], [ 2, 3 ] ], - [ [ 1, 2 ], [ 1, 2 ] ] - ]; - - expected = [ - [ 1, 2 ], - [ 3, 4 ], - [ 5, 6, 7 ], - [ 3, 3 ], - [ 3 ], - [ 3, 2 ], - [ 2, 3 ], - [ 1, 2 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty dims)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 1, 0 ], [ 0, 0 ] ], - [ [ 0, 1 ], [ 0, 0 ] ], - [ [ 1, 0 ], [ 0, 1 ] ], - [ [ 1, 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 1, 0 ] ], - [ [ 1, 1 ], [ 0, 1 ] ], - [ [ 0 ], [ 0, 0 ] ], - [ [ 0 ], [ 0, 1 ] ], - [ [ 1 ], [ 0, 0 ] ], - [ [ 1, 1 ], [ 0 ] ], - [ [ 1 ], [ 0, 1 ] ], - [ [ 1 ], [ 1, 0 ] ], - [ [ 1 ], [ 8, 0 ] ], - [ [ 8, 1, 6, 1 ], [ 0, 1, 5 ] ], - [ [ 8, 0, 6, 1 ], [ 1, 5 ] ] - ]; - - expected = [ - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 0, 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 1, 0 ], - [ 8, 0 ], - [ 8, 0, 6, 5 ], - [ 8, 0, 6, 5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (no shapes)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [] - ]; - - expected = [ - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (empty shapes (i.e., zero-dimensional array broadcasting))', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [] ], - [ [], [] ], - [ [], [], [] ], - [ [], [ 0 ] ], - [ [ 0 ], [] ], - [ [], [ 0, 0 ] ], - [ [ 0, 0 ], [] ], - [ [], [ 1, 0 ] ], - [ [], [ 0, 1 ] ], - [ [], [ 3, 3 ] ], - [ [], [ 3, 3 ], [] ] - ]; - - expected = [ - [], - [], - [], - [ 0 ], - [ 0 ], - [ 0, 0 ], - [ 0, 0 ], - [ 1, 0 ], - [ 0, 1 ], - [ 3, 3 ], - [ 3, 3 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function broadcasts array shapes to a single shape (single shape)', function test( t ) { - var expected; - var actual; - var values; - var i; - - values = [ - [ [ 7 ] ], - [ [ 1, 1 ] ], - [ [ 5, 6, 1 ] ] - ]; - - expected = [ - [ 7 ], - [ 1, 1 ], - [ 5, 6, 1 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.deepEqual( actual, expected[ i ], 'returns expected value. Actual: ('+actual.join( ',' )+'). Expected: ('+expected[ i ].join( ',' )+').' ); - } - t.end(); -}); - -tape( 'the function returns `null` if provided incompatible shapes', function test( t ) { - var actual; - var values; - var i; - - values = [ - [ [ 3 ], [ 4 ] ], - [ [ 2, 3 ], [ 2 ] ], - [ [ 3 ], [ 3 ], [ 4 ] ], - [ [ 1, 3, 4 ], [ 2, 3, 3 ] ], - [ [ 1, 2 ], [ 3, 1 ], [ 3, 2 ], [ 10, 5 ] ], - [ [ 2 ], [ 2, 3 ] ], - [ [ 2 ], [ 2 ], [ 2 ], [ 2 ], [ 3 ], [ 3 ], [ 3 ], [ 3 ] ], - [ [ 9, 0, 9 ], [ 0, 9, 0 ] ], - [ [ 9, 9, 9 ], [ 0, 9, 9 ] ], - [ [ 9, 0, 9 ], [ 9, 9, 9 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 0 ] ] - ]; - - for ( i = 0; i < values.length; i++ ) { - actual = broadcastShapes( values[ i ] ); - t.strictEqual( actual, null, 'returns expected value. i: '+i+'.' ); - } - t.end(); -});