From 90dfea4aa9b25c5570aeaab67909db378dee8e26 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Apr 2022 12:00:06 +0000 Subject: [PATCH 001/119] Auto-generated commit 1e86613ea46146936a701b5b5787867ec4842680 --- CONTRIBUTORS | 28 + LICENSE | 481 +++++++++ NOTICE | 1 + README.md | 223 ++++ index.d.ts | 81 ++ index.mjs | 4 + index.mjs.map | 1 + package.json | 36 + stats.html | 2689 +++++++++++++++++++++++++++++++++++++++++++++++++ 9 files changed, 3544 insertions(+) create mode 100644 CONTRIBUTORS create mode 100644 LICENSE create mode 100644 NOTICE create mode 100644 README.md create mode 100644 index.d.ts create mode 100644 index.mjs create mode 100644 index.mjs.map create mode 100644 package.json create mode 100644 stats.html diff --git a/CONTRIBUTORS b/CONTRIBUTORS new file mode 100644 index 0000000..e5c896d --- /dev/null +++ b/CONTRIBUTORS @@ -0,0 +1,28 @@ +# This file is generated by tools/scripts/update_contributors. +# +# Contributors listed in alphabetical order. + +Ali Salesi +Athan Reines +Brendan Graetz +Bruno Fenzl +Christopher Dambamuromo +Dominik Moritz +Frank Kovacs +James +Jithin KS +Joey Reed +Joris Labie +Justin Dennison +Marcus +Matt Cochrane +Milan Raj +Momtchil Momtchev +Ognjen Jevremović +Philipp Burckhardt +Ricky Reusser +Ryan Seal +Seyyed Parsa Neshaei +Shraddheya Shendre +dorrin-sot <59933477+dorrin-sot@users.noreply.github.com> +rei2hu diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..fcc9934 --- /dev/null +++ b/LICENSE @@ -0,0 +1,481 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + + +Boost Software License - Version 1.0 - August 17th, 2003 + +Permission is hereby granted, free of charge, to any person or organization +obtaining a copy of the software and accompanying documentation covered by this +license (the "Software") to use, reproduce, display, distribute, execute, and +transmit the Software, and to prepare derivative works of the Software, and to +permit third-parties to whom the Software is furnished to do so, all subject to +the following: + +The copyright notices in the Software and this entire statement, including the +above license grant, this restriction and the following disclaimer, must be +included in all copies of the Software, in whole or in part, and all derivative +works of the Software, unless such copies or derivative works are solely in the +form of machine-executable object code generated by a source language processor. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE +COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES +OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF +OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + + + +DEPENDENCIES + +The library links against the following external libraries, which have their own +licenses: + +* OpenBLAS + +Copyright (c) 2011-2014, The OpenBLAS Project +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + + 3. Neither the name of the OpenBLAS project nor the names of + its contributors may be used to endorse or promote products + derived from this software without specific prior written + permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE +GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF +THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + +* Electron + +Copyright (c) 2013-2017 GitHub Inc. + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + +* Boost + +Boost Software License - Version 1.0 - August 17th, 2003 + +Permission is hereby granted, free of charge, to any person or organization +obtaining a copy of the software and accompanying documentation covered by +this license (the "Software") to use, reproduce, display, distribute, +execute, and transmit the Software, and to prepare derivative works of the +Software, and to permit third-parties to whom the Software is furnished to +do so, all subject to the following: + +The copyright notices in the Software and this entire statement, including +the above license grant, this restriction and the following disclaimer, +must be included in all copies of the Software, in whole or in part, and +all derivative works of the Software, unless such copies or derivative +works are solely in the form of machine-executable object code generated by +a source language processor. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. + + +* Cephes + +Copyright (c) 1984-2000 Stephen L. Moshier + +Some software in this archive may be from the book _Methods and Programs for +Mathematical Functions_ (Prentice-Hall or Simon & Schuster International, 1989) +or from the Cephes Mathematical Library, a commercial product. In either event, +it is copyrighted by the author. What you see here may be used freely but it +comes with no support or guarantee. + +Stephen L. Moshier +moshier@na-net.ornl.gov + + + +ATTRIBUTION + +The library contains implementations from the following external libraries, +which have their own licenses: + +* FreeBSD + +Copyright (C) 1993-2004 by Sun Microsystems, Inc. All rights reserved. + +Developed at SunPro, a Sun Microsystems, Inc. business. +Permission to use, copy, modify, and distribute this +software is freely granted, provided that this notice +is preserved. + + +* FDLIBM + +Copyright (C) 2004 by Sun Microsystems, Inc. All rights reserved. + +Developed at SunPro, a Sun Microsystems, Inc. business. +Permission to use, copy, modify, and distribute this +software is freely granted, provided that this notice +is preserved. + + +* Go + +Copyright (c) 2009 The Go Authors. All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + * Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above +copyright notice, this list of conditions and the following disclaimer +in the documentation and/or other materials provided with the +distribution. + * Neither the name of Google Inc. nor the names of its +contributors may be used to endorse or promote products derived from +this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + +* SLATEC Common Mathematical Library + +Public domain. + + +* ESLint + +Copyright JS Foundation and other contributors, https://js.foundation + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + + +* StatsFuns.jl + +Copyright (c) 2015: Dahua Lin. + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + +* SpecialFunctions.jl + +The MIT License (MIT) + +Copyright (c) 2017 Jeff Bezanson, Stefan Karpinski, Viral B. Shah, and others: + +https://github.com/JuliaMath/SpecialFunctions.jl/graphs/contributors + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + + +* MT19937 + +Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura, +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + 3. The names of its contributors may not be used to endorse or promote + products derived from this software without specific prior written + permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/NOTICE b/NOTICE new file mode 100644 index 0000000..10e6ba1 --- /dev/null +++ b/NOTICE @@ -0,0 +1 @@ +Copyright (c) 2016-2022 The Stdlib Authors. diff --git a/README.md b/README.md new file mode 100644 index 0000000..ece6164 --- /dev/null +++ b/README.md @@ -0,0 +1,223 @@ + + +# maybeBroadcastArray + +[![NPM version][npm-image]][npm-url] [![Build Status][test-image]][test-url] [![Coverage Status][coverage-image]][coverage-url] + +> Broadcast an [ndarray][@stdlib/ndarray/base/ctor] to a specified shape if and only if the specified shape differs from the provided [ndarray][@stdlib/ndarray/base/ctor]'s shape. + + + +
+ +
+ + + + + + + +
+ +## Usage + +```javascript +import maybeBroadcastArray from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-maybe-broadcast-array@esm/index.mjs'; +``` + +#### maybeBroadcastArray( arr, shape ) + +Broadcasts an [ndarray][@stdlib/ndarray/base/ctor] to a specified `shape` if and only if the specified `shape` differs from the provided [ndarray][@stdlib/ndarray/base/ctor]'s shape. + +```javascript +import array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-array@esm/index.mjs'; + +// Create a 2x2 ndarray: +var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); +// returns + +// Broadcast to a 2x2x2 ndarray: +var y = maybeBroadcastArray( x, [ 2, 2, 2 ] ); +// returns +``` + +
+ + + + + +
+ +## Notes + +- The function throws an error if a provided [ndarray][@stdlib/ndarray/base/ctor] is [incompatible][@stdlib/ndarray/base/broadcast-shapes] with a provided shape. +- If a provided [ndarray][@stdlib/ndarray/base/ctor] has the same shape as the specified shape, the function returns the provided [ndarray][@stdlib/ndarray/base/ctor]. +- If a provided [ndarray][@stdlib/ndarray/base/ctor] has a different (broadcast compatible) shape than the specified shape, the function returns a new (base) [ndarray][@stdlib/ndarray/base/ctor] view of the provided [ndarray][@stdlib/ndarray/base/ctor]'s data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to the view may affect multiple elements. If you need to write to the returned [ndarray][@stdlib/ndarray/base/ctor], copy the [ndarray][@stdlib/ndarray/base/ctor] **before** performing operations which may mutate elements. +- A returned [ndarray][@stdlib/ndarray/base/ctor] is a "base" [ndarray][@stdlib/ndarray/base/ctor], and, thus, a returned [ndarray][@stdlib/ndarray/base/ctor] view does not perform bounds checking or afford any of the guarantees of the non-base [ndarray][@stdlib/ndarray/ctor] constructor. The primary intent of this function is to broadcast an ndarray-like object within internal implementations and to do so with minimal overhead. + +
+ + + + + +
+ +## Examples + + + +```html + + + + + + +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + +
+ +* * * + +## Notice + +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. + +For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. + +#### Community + +[![Chat][chat-image]][chat-url] + +--- + +## License + +See [LICENSE][stdlib-license]. + + +## Copyright + +Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. + +
+ + + + + + + + diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..c60cbe5 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,81 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2022 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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'; +import { ndarray } from '@stdlib/types/ndarray'; + +/** +* Broadcasts an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. +* +* ## Notes +* +* - The function throws an error if a provided ndarray is incompatible with a provided shape. +* - If a provided ndarray has the same shape as the specified shape, the function returns the provided ndarray. +* - If a provided ndarray has a different (broadcast compatible) shape than the specified shape, the function returns a new (base) ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to the view may affect multiple elements. If you need to write to the returned array, copy the array before performing operations which may mutate elements. +* - A returned array view is a "base" ndarray, and, thus, a returned array view does not perform bounds checking or afford any of the guarantees of the non-base ndarray constructor. The primary intent of this function is to broadcast an ndarray-like object within internal implementations and to do so with minimal overhead. +* +* @param arr - input array +* @param shape - desired shape +* @throws input array cannot have more dimensions than the desired shape +* @throws input array dimension sizes must be `1` or equal to the corresponding dimension in the provided shape +* @throws input array and desired shape must be broadcast compatible +* @returns broadcasted array +* +* @example +* var array = require( `@stdlib/ndarray/array` ); +* +* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); +* // returns +* +* var shx = x.shape; +* // returns [ 2, 2 ] +* +* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); +* // returns +* +* var shy = y.shape; +* // returns [ 3, 2, 2 ] +* +* var v = y.get( 0, 0, 0 ); +* // returns 1 +* +* v = y.get( 0, 0, 1 ); +* // returns 2 +* +* v = y.get( 1, 0, 0 ); +* // returns 1 +* +* v = y.get( 1, 1, 0 ); +* // returns 3 +* +* v = y.get( 2, 0, 0 ); +* // returns 1 +* +* v = y.get( 2, 1, 1 ); +* // returns 4 +*/ +declare function maybeBroadcastArray( arr: ndarray, shape: ArrayLike ): ndarray; // tslint:disable-line:max-line-length + + +// EXPORTS // + +export = maybeBroadcastArray; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..88a8567 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@esm/index.mjs";var t=r;var a=function(r,a){var e,n,s;if(n=a.length,(e=r.shape).length===n){for(s=0;s\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = arr.shape;\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nmodule.exports = maybeBroadcastArray;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape.\n*\n* @module @stdlib/ndarray-base-maybe-broadcast-array\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var maybeBroadcastArray = require( '@stdlib/ndarray-base-maybe-broadcast-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"],"names":["broadcast","require$$0","lib","arr","shape","sh","N","i","length"],"mappings":";;gGAsBA,IAAIA,EAAYC,EAwFhB,IC3CAC,EDiBA,SAA8BC,EAAKC,GAClC,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAMI,QACVH,EAAKF,EAAIC,OAGDI,SAAWF,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,KAAQH,EAAOG,GAEvB,OAAOP,EAAWG,EAAKC,GAGzB,OAAOD,EAGR,OAAOH,EAAWG,EAAKC"} \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..e8ffc0e --- /dev/null +++ b/package.json @@ -0,0 +1,36 @@ +{ + "name": "@stdlib/ndarray-base-maybe-broadcast-array", + "version": "0.0.0", + "description": "Broadcast an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape.", + "license": "Apache-2.0", + "type": "module", + "main": "./index.mjs", + "homepage": "https://stdlib.io", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/ndarray-base-maybe-broadcast-array.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "keywords": [ + "stdlib", + "stdtypes", + "types", + "base", + "ndarray", + "broadcast", + "broadcasting", + "reshape", + "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..2a66bba --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + From 3eba7bd4c1738e01035c3971b9919589ef617a1d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Jul 2022 01:03:35 +0000 Subject: [PATCH 002/119] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index f2a827c..6083467 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ }, "dependencies": { "@stdlib/ndarray-base-broadcast-array": "^0.0.x", - "@stdlib/types": "^0.0.x" + "@stdlib/types": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x" }, "devDependencies": { "@stdlib/array-float64": "^0.0.x", @@ -89,4 +90,4 @@ "type": "patreon", "url": "https://www.patreon.com/athan" } -} +} \ No newline at end of file From be7a6188ce74a40e1ac9011097d2c9772bf9fe89 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Jul 2022 16:06:24 +0000 Subject: [PATCH 003/119] Remove files --- index.d.ts | 81 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2775 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index c60cbe5..0000000 --- a/index.d.ts +++ /dev/null @@ -1,81 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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'; -import { ndarray } from '@stdlib/types/ndarray'; - -/** -* Broadcasts an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* ## Notes -* -* - The function throws an error if a provided ndarray is incompatible with a provided shape. -* - If a provided ndarray has the same shape as the specified shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the specified shape, the function returns a new (base) ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to the view may affect multiple elements. If you need to write to the returned array, copy the array before performing operations which may mutate elements. -* - A returned array view is a "base" ndarray, and, thus, a returned array view does not perform bounds checking or afford any of the guarantees of the non-base ndarray constructor. The primary intent of this function is to broadcast an ndarray-like object within internal implementations and to do so with minimal overhead. -* -* @param arr - input array -* @param shape - desired shape -* @throws input array cannot have more dimensions than the desired shape -* @throws input array dimension sizes must be `1` or equal to the corresponding dimension in the provided shape -* @throws input array and desired shape must be broadcast compatible -* @returns broadcasted array -* -* @example -* var array = require( `@stdlib/ndarray/array` ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -*/ -declare function maybeBroadcastArray( arr: ndarray, shape: ArrayLike ): ndarray; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = maybeBroadcastArray; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 88a8567..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@esm/index.mjs";var t=r;var a=function(r,a){var e,n,s;if(n=a.length,(e=r.shape).length===n){for(s=0;s\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = arr.shape;\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nmodule.exports = maybeBroadcastArray;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape.\n*\n* @module @stdlib/ndarray-base-maybe-broadcast-array\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var maybeBroadcastArray = require( '@stdlib/ndarray-base-maybe-broadcast-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"],"names":["broadcast","require$$0","lib","arr","shape","sh","N","i","length"],"mappings":";;gGAsBA,IAAIA,EAAYC,EAwFhB,IC3CAC,EDiBA,SAA8BC,EAAKC,GAClC,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAMI,QACVH,EAAKF,EAAIC,OAGDI,SAAWF,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,KAAQH,EAAOG,GAEvB,OAAOP,EAAWG,EAAKC,GAGzB,OAAOD,EAGR,OAAOH,EAAWG,EAAKC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 2a66bba..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 2cc92062c46657bff1acbb011ae9044796facced Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Jul 2022 16:07:19 +0000 Subject: [PATCH 004/119] 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 | 47 +- benchmark/benchmark.js | 290 --- benchmark/benchmark.ndims.js | 110 - branches.md | 53 - docs/repl.txt | 74 - docs/types/test.ts | 94 - examples/index.js | 45 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 68 - lib/main.js | 111 - package.json | 63 +- stats.html | 2689 +++++++++++++++++++++ test/test.js | 514 ---- 38 files changed, 2718 insertions(+), 4296 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/benchmark.ndims.js delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (97%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/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 234c89c..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-06-30T22:38:12.925Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 740d5ce..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/maybe-broadcast-array) 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 3740889..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/maybe-broadcast-array) 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 + + ```
@@ -160,7 +153,7 @@ for ( i = 0; i < N; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -220,11 +213,11 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-maybe-broadcast-array/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor +[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor/tree/esm -[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes +[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 9763740..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,290 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var ndarrayBase = require( '@stdlib/ndarray-base-ctor' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArray = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::base_ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::base_ndarray,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( out.shape[ 0 ] !== shape[ 0 ] ) { - b.fail( 'unexpected result' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.ndims.js b/benchmark/benchmark.ndims.js deleted file mode 100644 index 1fa371b..0000000 --- a/benchmark/benchmark.ndims.js +++ /dev/null @@ -1,110 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var array = require( '@stdlib/ndarray-array' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} ndims - number of dimensions to which to broadcast -* @returns {Function} benchmark function -*/ -function createBenchmark( ndims ) { - var shape; - var sh; - var x; - var i; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - sh = x.shape; - - shape = []; - for ( i = 0; i < ndims; i++ ) { - shape.push( 0 ); - } - for ( i = ndims; i >= 1; i-- ) { - if ( i > shape.length ) { - shape[ ndims-i ] = 5; - } else { - shape[ ndims-i ] = sh[ i-1 ]; - } - } - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( x, shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var min; - var max; - var f; - var i; - - min = 2; - max = 10; - - for ( i = min; i <= max; i++ ) { - f = createBenchmark( i ); - bench( pkg+'::ndarray,2d:from_ndims=2,to_ndims='+i, f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index b75f357..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/maybe-broadcast-array" -click B href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/main" -click C href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/production" -click D href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/maybe-broadcast-array -[production-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 93528fb..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,74 +0,0 @@ - -{{alias}}( arr, shape ) - Broadcasts an ndarray to a specified shape if and only if the specified - shape differs from the provided ndarray's shape. - - If a provided ndarray has the same shape as the specified shape, the - function returns the provided ndarray. - - If a provided ndarray has a different (broadcast compatible) shape than the - specified shape, the function returns a new (base) ndarray view of the - provided ndarray's data. The view is typically **not** contiguous. As more - than one element of a returned view may refer to the same memory location, - writing to the view may affect multiple elements. If you need to write to - the returned array, copy the array before performing operations which may - mutate elements. - - A returned array is a view on the input array data buffer. The view is - typically *not* contiguous. As more than one element of a returned view may - refer to the same memory location, writing to the view may affect multiple - elements. If you need to write to the returned array, copy the array before - performing operations which may mutate elements. - - A returned array view is a "base" ndarray, and, thus, a returned array view - does not perform bounds checking or afford any of the guarantees of the non- - base ndarray constructor. The primary intent of this function is to - broadcast an ndarray-like object within internal implementations and to do - so with minimal overhead. - - The function throws an error if a provided ndarray is incompatible with a - provided shape. - - Parameters - ---------- - arr: ndarray - Input array. - - shape: ArrayLikeObject - Desired shape. - - Returns - ------- - out: ndarray - Broadcasted array. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > var sh = x.shape - [ 2, 2 ] - > var y = {{alias}}( x, [ 3, 2, 2 ] ) - - > sh = y.shape - [ 3, 2, 2 ] - > var v = y.get( 0, 0, 0 ) - 1 - > v = y.get( 0, 0, 1 ) - 2 - > v = y.get( 0, 1, 0 ) - 3 - > v = y.get( 0, 1, 1 ) - 4 - > v = y.get( 1, 0, 0 ) - 1 - > v = y.get( 1, 1, 0 ) - 3 - > v = y.get( 2, 0, 0 ) - 1 - > v = y.get( 2, 1, 1 ) - 4 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index d7a1a62..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,94 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ndarray } from '@stdlib/types/ndarray'; -import maybeBroadcastArray = require( './index' ); - -/** -* Mock function to create an ndarray-like object. -* -* @return ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns an ndarray... -{ - const x = array(); - - maybeBroadcastArray( x, [ 2, 2, 2 ] ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is not provided a first argument which is an ndarray... -{ - maybeBroadcastArray( '5', [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( 5, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( true, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( false, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( null, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( {}, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( [ '5' ], [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( ( x: number ): number => x, [ 2, 2, 2 ] ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a second argument which is an array-like object containing numbers... -{ - const x = array(); - - maybeBroadcastArray( x, '5' ); // $ExpectError - maybeBroadcastArray( x, 5 ); // $ExpectError - maybeBroadcastArray( x, true ); // $ExpectError - maybeBroadcastArray( x, false ); // $ExpectError - maybeBroadcastArray( x, null ); // $ExpectError - maybeBroadcastArray( x, {} ); // $ExpectError - maybeBroadcastArray( x, [ '5' ] ); // $ExpectError - maybeBroadcastArray( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - - maybeBroadcastArray(); // $ExpectError - maybeBroadcastArray( x ); // $ExpectError - maybeBroadcastArray( x, [ 1, 2, 3 ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index e787d6e..0000000 --- a/examples/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 array = require( '@stdlib/ndarray-array' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var maybeBroadcastArray = require( './../lib' ); - -// Create a 2x2 array: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -// returns - -// Broadcast the array to 3x2x2: -var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -// returns - -// Retrieve the shape: -var sh = y.shape; -// returns [ 3, 2, 2 ] - -// Retrieve the number of elements: -var N = numel( sh ); - -// Loop through the array elements... -var i; -for ( i = 0; i < N; i++ ) { - console.log( 'Y[%s] = %d', ind2sub( sh, i ).join( ', ' ), y.iget( i ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 97% rename from docs/types/index.d.ts rename to index.d.ts index 6c11bdd..c60cbe5 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..eeac6bf --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@esm/index.mjs";function t(t,e){var a,n,s;if(n=e.length,(a=t.shape).length===n){for(s=0;s\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import array from '@stdlib/ndarray-array' ;\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = arr.shape;\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArray;\n"],"names":["maybeBroadcastArray","arr","shape","sh","N","i","length","broadcast"],"mappings":";;gGAoFA,SAASA,EAAqBC,EAAKC,GAClC,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAMI,QACVH,EAAKF,EAAIC,OAGDI,SAAWF,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,KAAQH,EAAOG,GAEvB,OAAOE,EAAWN,EAAKC,GAGzB,OAAOD,EAGR,OAAOM,EAAWN,EAAKC"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 834e930..0000000 --- a/lib/index.js +++ /dev/null @@ -1,68 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* @module @stdlib/ndarray-base-maybe-broadcast-array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var maybeBroadcastArray = require( '@stdlib/ndarray-base-maybe-broadcast-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -*/ - -// 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 278f868..0000000 --- a/lib/main.js +++ /dev/null @@ -1,111 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var broadcast = require( '@stdlib/ndarray-base-broadcast-array' ); - - -// MAIN // - -/** -* Broadcasts an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* ## Notes -* -* - If a provided ndarray has the same shape as the specified shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the specified shape, the function returns a new (base) ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to the view may affect multiple elements. If you need to write to the returned array, copy the array before performing operations which may mutate elements. -* -* @param {ndarray} arr - input array -* @param {NonNegativeIntegerArray} shape - desired shape -* @throws {Error} input array cannot have more dimensions than the desired shape -* @throws {Error} input array dimension sizes must be `1` or equal to the corresponding dimension in the provided shape -* @throws {Error} input array and desired shape must be broadcast compatible -* @returns {ndarray} broadcasted array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var y = maybeBroadcastArray( x, [ 3, 2 ] ); -* // throws -*/ -function maybeBroadcastArray( arr, shape ) { - var sh; - var N; - var i; - - N = shape.length; - sh = arr.shape; - - // Check whether we need to broadcast the input array... - if ( sh.length === N ) { - for ( i = 0; i < N; i++ ) { - // Check whether dimensions match... - if ( sh[ i ] !== shape[ i ] ) { - // We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape... - return broadcast( arr, shape ); - } - } - return arr; - } - // If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape... - return broadcast( arr, shape ); -} - - -// EXPORTS // - -module.exports = maybeBroadcastArray; diff --git a/package.json b/package.json index 6083467..97dd5d7 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.1", "description": "Broadcast an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's 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", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,39 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-base-broadcast-array": "^0.0.x", - "@stdlib/types": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.0.x", - "@stdlib/assert-is-ndarray-like": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/ndarray-array": "^0.0.x", - "@stdlib/ndarray-base-ctor": "^0.0.x", - "@stdlib/ndarray-base-numel": "^0.0.x", - "@stdlib/ndarray-ctor": "^0.0.x", - "@stdlib/ndarray-ind2sub": "^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", @@ -85,9 +29,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..7cbeec0 --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 7e8e63f..0000000 --- a/test/test.js +++ /dev/null @@ -1,514 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 array = require( '@stdlib/ndarray-array' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var maybeBroadcastArray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof maybeBroadcastArray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a desired shape which has fewer dimensions than the input array', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 ] - }); - - values = [ - [], - [ 2 ], - [ 2, 2 ], - [ 2, 2, 2 ], - [ 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2, 2, 2 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided a shape with '+values[ i ].length+' dimension' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape having a dimension whose size is less than the corresponding dimension in the input array', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 10, 1 ], - [ 10, 10, 2 ], - [ 10, 10, 9 ], - [ 10, 1, 10 ], - [ 10, 2, 10 ], - [ 10, 9, 10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape and an input array shape which are broadcast-incompatible', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 20, 10 ], - [ 10, 10, 100 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function returns a "base" ndarray instance', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = maybeBroadcastArray( x, [ 2, 2, 2 ] ); - - t.notEqual( y, x, 'returns new instance' ); - t.strictEqual( y instanceof ndarray, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view over the input array data buffer', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = maybeBroadcastArray( x, [ 2, 2, 2 ] ); - - t.strictEqual( y.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; strides)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, -1 ], 3, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; strides)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, 1 ], 2, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; non-contiguous)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ 4, 2 ], 1, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 5 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 7 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (column-major)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'column-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (same shape)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2, 2 ], - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - // Should return the same instance: - t.strictEqual( y, x, 'returns expected value' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 1, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 1, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (same number of dimensions)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1, 2 ], - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (singleton dimension)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (singleton dimension)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 1, 2 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (0-dimensional array)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1 ]; - x = ndarray( 'generic', data, [], [ 0 ], 0, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); From 7f6fd9ca4b42452b30c8e4f66a6906b14cf268d7 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Jul 2022 18:14:28 +0000 Subject: [PATCH 005/119] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index f2a827c..6083467 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ }, "dependencies": { "@stdlib/ndarray-base-broadcast-array": "^0.0.x", - "@stdlib/types": "^0.0.x" + "@stdlib/types": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x" }, "devDependencies": { "@stdlib/array-float64": "^0.0.x", @@ -89,4 +90,4 @@ "type": "patreon", "url": "https://www.patreon.com/athan" } -} +} \ No newline at end of file From aea661ac67af36eab7748264b5e790c38e4b907a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 2 Jul 2022 08:41:03 +0000 Subject: [PATCH 006/119] Remove files --- index.d.ts | 81 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2775 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index c60cbe5..0000000 --- a/index.d.ts +++ /dev/null @@ -1,81 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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'; -import { ndarray } from '@stdlib/types/ndarray'; - -/** -* Broadcasts an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* ## Notes -* -* - The function throws an error if a provided ndarray is incompatible with a provided shape. -* - If a provided ndarray has the same shape as the specified shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the specified shape, the function returns a new (base) ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to the view may affect multiple elements. If you need to write to the returned array, copy the array before performing operations which may mutate elements. -* - A returned array view is a "base" ndarray, and, thus, a returned array view does not perform bounds checking or afford any of the guarantees of the non-base ndarray constructor. The primary intent of this function is to broadcast an ndarray-like object within internal implementations and to do so with minimal overhead. -* -* @param arr - input array -* @param shape - desired shape -* @throws input array cannot have more dimensions than the desired shape -* @throws input array dimension sizes must be `1` or equal to the corresponding dimension in the provided shape -* @throws input array and desired shape must be broadcast compatible -* @returns broadcasted array -* -* @example -* var array = require( `@stdlib/ndarray/array` ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -*/ -declare function maybeBroadcastArray( arr: ndarray, shape: ArrayLike ): ndarray; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = maybeBroadcastArray; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index eeac6bf..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@esm/index.mjs";function t(t,e){var a,n,s;if(n=e.length,(a=t.shape).length===n){for(s=0;s\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import array from '@stdlib/ndarray-array' ;\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = arr.shape;\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArray;\n"],"names":["maybeBroadcastArray","arr","shape","sh","N","i","length","broadcast"],"mappings":";;gGAoFA,SAASA,EAAqBC,EAAKC,GAClC,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAMI,QACVH,EAAKF,EAAIC,OAGDI,SAAWF,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,KAAQH,EAAOG,GAEvB,OAAOE,EAAWN,EAAKC,GAGzB,OAAOD,EAGR,OAAOM,EAAWN,EAAKC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 7cbeec0..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From bdb4bf94ae026bba255f10a6d334af6e6417d50c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 2 Jul 2022 08:41:55 +0000 Subject: [PATCH 007/119] 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 | 47 +- benchmark/benchmark.js | 290 --- benchmark/benchmark.ndims.js | 110 - branches.md | 53 - docs/repl.txt | 74 - docs/types/test.ts | 94 - examples/index.js | 45 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 68 - lib/main.js | 111 - package.json | 63 +- stats.html | 2689 +++++++++++++++++++++ test/test.js | 514 ---- 38 files changed, 2718 insertions(+), 4296 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/benchmark.ndims.js delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (97%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/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 bcd90a3..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-07-01T01:32:20.799Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 740d5ce..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/maybe-broadcast-array) 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 3740889..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/maybe-broadcast-array) 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 + + ```
@@ -160,7 +153,7 @@ for ( i = 0; i < N; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -220,11 +213,11 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-maybe-broadcast-array/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor +[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor/tree/esm -[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes +[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 9763740..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,290 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var ndarrayBase = require( '@stdlib/ndarray-base-ctor' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArray = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::base_ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::base_ndarray,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( out.shape[ 0 ] !== shape[ 0 ] ) { - b.fail( 'unexpected result' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.ndims.js b/benchmark/benchmark.ndims.js deleted file mode 100644 index 1fa371b..0000000 --- a/benchmark/benchmark.ndims.js +++ /dev/null @@ -1,110 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var array = require( '@stdlib/ndarray-array' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} ndims - number of dimensions to which to broadcast -* @returns {Function} benchmark function -*/ -function createBenchmark( ndims ) { - var shape; - var sh; - var x; - var i; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - sh = x.shape; - - shape = []; - for ( i = 0; i < ndims; i++ ) { - shape.push( 0 ); - } - for ( i = ndims; i >= 1; i-- ) { - if ( i > shape.length ) { - shape[ ndims-i ] = 5; - } else { - shape[ ndims-i ] = sh[ i-1 ]; - } - } - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( x, shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var min; - var max; - var f; - var i; - - min = 2; - max = 10; - - for ( i = min; i <= max; i++ ) { - f = createBenchmark( i ); - bench( pkg+'::ndarray,2d:from_ndims=2,to_ndims='+i, f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index b75f357..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/maybe-broadcast-array" -click B href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/main" -click C href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/production" -click D href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/maybe-broadcast-array -[production-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 93528fb..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,74 +0,0 @@ - -{{alias}}( arr, shape ) - Broadcasts an ndarray to a specified shape if and only if the specified - shape differs from the provided ndarray's shape. - - If a provided ndarray has the same shape as the specified shape, the - function returns the provided ndarray. - - If a provided ndarray has a different (broadcast compatible) shape than the - specified shape, the function returns a new (base) ndarray view of the - provided ndarray's data. The view is typically **not** contiguous. As more - than one element of a returned view may refer to the same memory location, - writing to the view may affect multiple elements. If you need to write to - the returned array, copy the array before performing operations which may - mutate elements. - - A returned array is a view on the input array data buffer. The view is - typically *not* contiguous. As more than one element of a returned view may - refer to the same memory location, writing to the view may affect multiple - elements. If you need to write to the returned array, copy the array before - performing operations which may mutate elements. - - A returned array view is a "base" ndarray, and, thus, a returned array view - does not perform bounds checking or afford any of the guarantees of the non- - base ndarray constructor. The primary intent of this function is to - broadcast an ndarray-like object within internal implementations and to do - so with minimal overhead. - - The function throws an error if a provided ndarray is incompatible with a - provided shape. - - Parameters - ---------- - arr: ndarray - Input array. - - shape: ArrayLikeObject - Desired shape. - - Returns - ------- - out: ndarray - Broadcasted array. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > var sh = x.shape - [ 2, 2 ] - > var y = {{alias}}( x, [ 3, 2, 2 ] ) - - > sh = y.shape - [ 3, 2, 2 ] - > var v = y.get( 0, 0, 0 ) - 1 - > v = y.get( 0, 0, 1 ) - 2 - > v = y.get( 0, 1, 0 ) - 3 - > v = y.get( 0, 1, 1 ) - 4 - > v = y.get( 1, 0, 0 ) - 1 - > v = y.get( 1, 1, 0 ) - 3 - > v = y.get( 2, 0, 0 ) - 1 - > v = y.get( 2, 1, 1 ) - 4 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index d7a1a62..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,94 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ndarray } from '@stdlib/types/ndarray'; -import maybeBroadcastArray = require( './index' ); - -/** -* Mock function to create an ndarray-like object. -* -* @return ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns an ndarray... -{ - const x = array(); - - maybeBroadcastArray( x, [ 2, 2, 2 ] ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is not provided a first argument which is an ndarray... -{ - maybeBroadcastArray( '5', [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( 5, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( true, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( false, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( null, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( {}, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( [ '5' ], [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( ( x: number ): number => x, [ 2, 2, 2 ] ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a second argument which is an array-like object containing numbers... -{ - const x = array(); - - maybeBroadcastArray( x, '5' ); // $ExpectError - maybeBroadcastArray( x, 5 ); // $ExpectError - maybeBroadcastArray( x, true ); // $ExpectError - maybeBroadcastArray( x, false ); // $ExpectError - maybeBroadcastArray( x, null ); // $ExpectError - maybeBroadcastArray( x, {} ); // $ExpectError - maybeBroadcastArray( x, [ '5' ] ); // $ExpectError - maybeBroadcastArray( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - - maybeBroadcastArray(); // $ExpectError - maybeBroadcastArray( x ); // $ExpectError - maybeBroadcastArray( x, [ 1, 2, 3 ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index e787d6e..0000000 --- a/examples/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 array = require( '@stdlib/ndarray-array' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var maybeBroadcastArray = require( './../lib' ); - -// Create a 2x2 array: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -// returns - -// Broadcast the array to 3x2x2: -var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -// returns - -// Retrieve the shape: -var sh = y.shape; -// returns [ 3, 2, 2 ] - -// Retrieve the number of elements: -var N = numel( sh ); - -// Loop through the array elements... -var i; -for ( i = 0; i < N; i++ ) { - console.log( 'Y[%s] = %d', ind2sub( sh, i ).join( ', ' ), y.iget( i ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 97% rename from docs/types/index.d.ts rename to index.d.ts index 6c11bdd..c60cbe5 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..eeac6bf --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@esm/index.mjs";function t(t,e){var a,n,s;if(n=e.length,(a=t.shape).length===n){for(s=0;s\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import array from '@stdlib/ndarray-array' ;\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = arr.shape;\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArray;\n"],"names":["maybeBroadcastArray","arr","shape","sh","N","i","length","broadcast"],"mappings":";;gGAoFA,SAASA,EAAqBC,EAAKC,GAClC,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAMI,QACVH,EAAKF,EAAIC,OAGDI,SAAWF,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,KAAQH,EAAOG,GAEvB,OAAOE,EAAWN,EAAKC,GAGzB,OAAOD,EAGR,OAAOM,EAAWN,EAAKC"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 834e930..0000000 --- a/lib/index.js +++ /dev/null @@ -1,68 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* @module @stdlib/ndarray-base-maybe-broadcast-array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var maybeBroadcastArray = require( '@stdlib/ndarray-base-maybe-broadcast-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -*/ - -// 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 278f868..0000000 --- a/lib/main.js +++ /dev/null @@ -1,111 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var broadcast = require( '@stdlib/ndarray-base-broadcast-array' ); - - -// MAIN // - -/** -* Broadcasts an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* ## Notes -* -* - If a provided ndarray has the same shape as the specified shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the specified shape, the function returns a new (base) ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to the view may affect multiple elements. If you need to write to the returned array, copy the array before performing operations which may mutate elements. -* -* @param {ndarray} arr - input array -* @param {NonNegativeIntegerArray} shape - desired shape -* @throws {Error} input array cannot have more dimensions than the desired shape -* @throws {Error} input array dimension sizes must be `1` or equal to the corresponding dimension in the provided shape -* @throws {Error} input array and desired shape must be broadcast compatible -* @returns {ndarray} broadcasted array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var y = maybeBroadcastArray( x, [ 3, 2 ] ); -* // throws -*/ -function maybeBroadcastArray( arr, shape ) { - var sh; - var N; - var i; - - N = shape.length; - sh = arr.shape; - - // Check whether we need to broadcast the input array... - if ( sh.length === N ) { - for ( i = 0; i < N; i++ ) { - // Check whether dimensions match... - if ( sh[ i ] !== shape[ i ] ) { - // We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape... - return broadcast( arr, shape ); - } - } - return arr; - } - // If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape... - return broadcast( arr, shape ); -} - - -// EXPORTS // - -module.exports = maybeBroadcastArray; diff --git a/package.json b/package.json index 6083467..97dd5d7 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.1", "description": "Broadcast an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's 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", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,39 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-base-broadcast-array": "^0.0.x", - "@stdlib/types": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.0.x", - "@stdlib/assert-is-ndarray-like": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/ndarray-array": "^0.0.x", - "@stdlib/ndarray-base-ctor": "^0.0.x", - "@stdlib/ndarray-base-numel": "^0.0.x", - "@stdlib/ndarray-ctor": "^0.0.x", - "@stdlib/ndarray-ind2sub": "^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", @@ -85,9 +29,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..649775b --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 7e8e63f..0000000 --- a/test/test.js +++ /dev/null @@ -1,514 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 array = require( '@stdlib/ndarray-array' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var maybeBroadcastArray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof maybeBroadcastArray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a desired shape which has fewer dimensions than the input array', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 ] - }); - - values = [ - [], - [ 2 ], - [ 2, 2 ], - [ 2, 2, 2 ], - [ 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2, 2, 2 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided a shape with '+values[ i ].length+' dimension' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape having a dimension whose size is less than the corresponding dimension in the input array', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 10, 1 ], - [ 10, 10, 2 ], - [ 10, 10, 9 ], - [ 10, 1, 10 ], - [ 10, 2, 10 ], - [ 10, 9, 10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape and an input array shape which are broadcast-incompatible', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 20, 10 ], - [ 10, 10, 100 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function returns a "base" ndarray instance', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = maybeBroadcastArray( x, [ 2, 2, 2 ] ); - - t.notEqual( y, x, 'returns new instance' ); - t.strictEqual( y instanceof ndarray, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view over the input array data buffer', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = maybeBroadcastArray( x, [ 2, 2, 2 ] ); - - t.strictEqual( y.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; strides)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, -1 ], 3, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; strides)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, 1 ], 2, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; non-contiguous)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ 4, 2 ], 1, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 5 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 7 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (column-major)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'column-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (same shape)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2, 2 ], - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - // Should return the same instance: - t.strictEqual( y, x, 'returns expected value' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 1, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 1, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (same number of dimensions)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1, 2 ], - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (singleton dimension)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (singleton dimension)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 1, 2 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (0-dimensional array)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1 ]; - x = ndarray( 'generic', data, [], [ 0 ], 0, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); From a9afeb927a0c56fd3bdc0d9d50678ca94724e15b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 6 Jul 2022 16:49:32 +0000 Subject: [PATCH 008/119] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index f2a827c..6083467 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ }, "dependencies": { "@stdlib/ndarray-base-broadcast-array": "^0.0.x", - "@stdlib/types": "^0.0.x" + "@stdlib/types": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x" }, "devDependencies": { "@stdlib/array-float64": "^0.0.x", @@ -89,4 +90,4 @@ "type": "patreon", "url": "https://www.patreon.com/athan" } -} +} \ No newline at end of file From 68af622d2715d3cb2403a5d5f866ec634a2c33bf Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 6 Jul 2022 16:49:58 +0000 Subject: [PATCH 009/119] Remove files --- index.d.ts | 81 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2775 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index c60cbe5..0000000 --- a/index.d.ts +++ /dev/null @@ -1,81 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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'; -import { ndarray } from '@stdlib/types/ndarray'; - -/** -* Broadcasts an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* ## Notes -* -* - The function throws an error if a provided ndarray is incompatible with a provided shape. -* - If a provided ndarray has the same shape as the specified shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the specified shape, the function returns a new (base) ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to the view may affect multiple elements. If you need to write to the returned array, copy the array before performing operations which may mutate elements. -* - A returned array view is a "base" ndarray, and, thus, a returned array view does not perform bounds checking or afford any of the guarantees of the non-base ndarray constructor. The primary intent of this function is to broadcast an ndarray-like object within internal implementations and to do so with minimal overhead. -* -* @param arr - input array -* @param shape - desired shape -* @throws input array cannot have more dimensions than the desired shape -* @throws input array dimension sizes must be `1` or equal to the corresponding dimension in the provided shape -* @throws input array and desired shape must be broadcast compatible -* @returns broadcasted array -* -* @example -* var array = require( `@stdlib/ndarray/array` ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -*/ -declare function maybeBroadcastArray( arr: ndarray, shape: ArrayLike ): ndarray; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = maybeBroadcastArray; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index eeac6bf..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@esm/index.mjs";function t(t,e){var a,n,s;if(n=e.length,(a=t.shape).length===n){for(s=0;s\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import array from '@stdlib/ndarray-array' ;\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = arr.shape;\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArray;\n"],"names":["maybeBroadcastArray","arr","shape","sh","N","i","length","broadcast"],"mappings":";;gGAoFA,SAASA,EAAqBC,EAAKC,GAClC,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAMI,QACVH,EAAKF,EAAIC,OAGDI,SAAWF,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,KAAQH,EAAOG,GAEvB,OAAOE,EAAWN,EAAKC,GAGzB,OAAOD,EAGR,OAAOM,EAAWN,EAAKC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 649775b..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 796a114700a069e588078b3f4c12d8db0b0a7f4c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 6 Jul 2022 16:50:53 +0000 Subject: [PATCH 010/119] 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 | 47 +- benchmark/benchmark.js | 290 --- benchmark/benchmark.ndims.js | 110 - branches.md | 53 - docs/repl.txt | 74 - docs/types/test.ts | 94 - examples/index.js | 45 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 68 - lib/main.js | 111 - package.json | 63 +- stats.html | 2689 +++++++++++++++++++++ test/test.js | 514 ---- 37 files changed, 2718 insertions(+), 4261 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/benchmark.ndims.js delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (97%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/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 740d5ce..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/maybe-broadcast-array) 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 3740889..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/maybe-broadcast-array) 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 + + ```
@@ -160,7 +153,7 @@ for ( i = 0; i < N; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -220,11 +213,11 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-maybe-broadcast-array/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor +[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor/tree/esm -[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes +[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 9763740..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,290 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var ndarrayBase = require( '@stdlib/ndarray-base-ctor' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArray = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::base_ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::base_ndarray,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( out.shape[ 0 ] !== shape[ 0 ] ) { - b.fail( 'unexpected result' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.ndims.js b/benchmark/benchmark.ndims.js deleted file mode 100644 index 1fa371b..0000000 --- a/benchmark/benchmark.ndims.js +++ /dev/null @@ -1,110 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var array = require( '@stdlib/ndarray-array' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} ndims - number of dimensions to which to broadcast -* @returns {Function} benchmark function -*/ -function createBenchmark( ndims ) { - var shape; - var sh; - var x; - var i; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - sh = x.shape; - - shape = []; - for ( i = 0; i < ndims; i++ ) { - shape.push( 0 ); - } - for ( i = ndims; i >= 1; i-- ) { - if ( i > shape.length ) { - shape[ ndims-i ] = 5; - } else { - shape[ ndims-i ] = sh[ i-1 ]; - } - } - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( x, shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var min; - var max; - var f; - var i; - - min = 2; - max = 10; - - for ( i = min; i <= max; i++ ) { - f = createBenchmark( i ); - bench( pkg+'::ndarray,2d:from_ndims=2,to_ndims='+i, f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index b75f357..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/maybe-broadcast-array" -click B href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/main" -click C href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/production" -click D href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/maybe-broadcast-array -[production-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 93528fb..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,74 +0,0 @@ - -{{alias}}( arr, shape ) - Broadcasts an ndarray to a specified shape if and only if the specified - shape differs from the provided ndarray's shape. - - If a provided ndarray has the same shape as the specified shape, the - function returns the provided ndarray. - - If a provided ndarray has a different (broadcast compatible) shape than the - specified shape, the function returns a new (base) ndarray view of the - provided ndarray's data. The view is typically **not** contiguous. As more - than one element of a returned view may refer to the same memory location, - writing to the view may affect multiple elements. If you need to write to - the returned array, copy the array before performing operations which may - mutate elements. - - A returned array is a view on the input array data buffer. The view is - typically *not* contiguous. As more than one element of a returned view may - refer to the same memory location, writing to the view may affect multiple - elements. If you need to write to the returned array, copy the array before - performing operations which may mutate elements. - - A returned array view is a "base" ndarray, and, thus, a returned array view - does not perform bounds checking or afford any of the guarantees of the non- - base ndarray constructor. The primary intent of this function is to - broadcast an ndarray-like object within internal implementations and to do - so with minimal overhead. - - The function throws an error if a provided ndarray is incompatible with a - provided shape. - - Parameters - ---------- - arr: ndarray - Input array. - - shape: ArrayLikeObject - Desired shape. - - Returns - ------- - out: ndarray - Broadcasted array. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > var sh = x.shape - [ 2, 2 ] - > var y = {{alias}}( x, [ 3, 2, 2 ] ) - - > sh = y.shape - [ 3, 2, 2 ] - > var v = y.get( 0, 0, 0 ) - 1 - > v = y.get( 0, 0, 1 ) - 2 - > v = y.get( 0, 1, 0 ) - 3 - > v = y.get( 0, 1, 1 ) - 4 - > v = y.get( 1, 0, 0 ) - 1 - > v = y.get( 1, 1, 0 ) - 3 - > v = y.get( 2, 0, 0 ) - 1 - > v = y.get( 2, 1, 1 ) - 4 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index d7a1a62..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,94 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ndarray } from '@stdlib/types/ndarray'; -import maybeBroadcastArray = require( './index' ); - -/** -* Mock function to create an ndarray-like object. -* -* @return ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns an ndarray... -{ - const x = array(); - - maybeBroadcastArray( x, [ 2, 2, 2 ] ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is not provided a first argument which is an ndarray... -{ - maybeBroadcastArray( '5', [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( 5, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( true, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( false, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( null, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( {}, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( [ '5' ], [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( ( x: number ): number => x, [ 2, 2, 2 ] ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a second argument which is an array-like object containing numbers... -{ - const x = array(); - - maybeBroadcastArray( x, '5' ); // $ExpectError - maybeBroadcastArray( x, 5 ); // $ExpectError - maybeBroadcastArray( x, true ); // $ExpectError - maybeBroadcastArray( x, false ); // $ExpectError - maybeBroadcastArray( x, null ); // $ExpectError - maybeBroadcastArray( x, {} ); // $ExpectError - maybeBroadcastArray( x, [ '5' ] ); // $ExpectError - maybeBroadcastArray( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - - maybeBroadcastArray(); // $ExpectError - maybeBroadcastArray( x ); // $ExpectError - maybeBroadcastArray( x, [ 1, 2, 3 ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index e787d6e..0000000 --- a/examples/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 array = require( '@stdlib/ndarray-array' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var maybeBroadcastArray = require( './../lib' ); - -// Create a 2x2 array: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -// returns - -// Broadcast the array to 3x2x2: -var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -// returns - -// Retrieve the shape: -var sh = y.shape; -// returns [ 3, 2, 2 ] - -// Retrieve the number of elements: -var N = numel( sh ); - -// Loop through the array elements... -var i; -for ( i = 0; i < N; i++ ) { - console.log( 'Y[%s] = %d', ind2sub( sh, i ).join( ', ' ), y.iget( i ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 97% rename from docs/types/index.d.ts rename to index.d.ts index 6c11bdd..c60cbe5 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..eeac6bf --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@esm/index.mjs";function t(t,e){var a,n,s;if(n=e.length,(a=t.shape).length===n){for(s=0;s\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import array from '@stdlib/ndarray-array' ;\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = arr.shape;\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArray;\n"],"names":["maybeBroadcastArray","arr","shape","sh","N","i","length","broadcast"],"mappings":";;gGAoFA,SAASA,EAAqBC,EAAKC,GAClC,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAMI,QACVH,EAAKF,EAAIC,OAGDI,SAAWF,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,KAAQH,EAAOG,GAEvB,OAAOE,EAAWN,EAAKC,GAGzB,OAAOD,EAGR,OAAOM,EAAWN,EAAKC"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 834e930..0000000 --- a/lib/index.js +++ /dev/null @@ -1,68 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* @module @stdlib/ndarray-base-maybe-broadcast-array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var maybeBroadcastArray = require( '@stdlib/ndarray-base-maybe-broadcast-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -*/ - -// 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 278f868..0000000 --- a/lib/main.js +++ /dev/null @@ -1,111 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var broadcast = require( '@stdlib/ndarray-base-broadcast-array' ); - - -// MAIN // - -/** -* Broadcasts an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* ## Notes -* -* - If a provided ndarray has the same shape as the specified shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the specified shape, the function returns a new (base) ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to the view may affect multiple elements. If you need to write to the returned array, copy the array before performing operations which may mutate elements. -* -* @param {ndarray} arr - input array -* @param {NonNegativeIntegerArray} shape - desired shape -* @throws {Error} input array cannot have more dimensions than the desired shape -* @throws {Error} input array dimension sizes must be `1` or equal to the corresponding dimension in the provided shape -* @throws {Error} input array and desired shape must be broadcast compatible -* @returns {ndarray} broadcasted array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var y = maybeBroadcastArray( x, [ 3, 2 ] ); -* // throws -*/ -function maybeBroadcastArray( arr, shape ) { - var sh; - var N; - var i; - - N = shape.length; - sh = arr.shape; - - // Check whether we need to broadcast the input array... - if ( sh.length === N ) { - for ( i = 0; i < N; i++ ) { - // Check whether dimensions match... - if ( sh[ i ] !== shape[ i ] ) { - // We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape... - return broadcast( arr, shape ); - } - } - return arr; - } - // If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape... - return broadcast( arr, shape ); -} - - -// EXPORTS // - -module.exports = maybeBroadcastArray; diff --git a/package.json b/package.json index 6083467..97dd5d7 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.1", "description": "Broadcast an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's 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", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,39 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-base-broadcast-array": "^0.0.x", - "@stdlib/types": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.0.x", - "@stdlib/assert-is-ndarray-like": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/ndarray-array": "^0.0.x", - "@stdlib/ndarray-base-ctor": "^0.0.x", - "@stdlib/ndarray-base-numel": "^0.0.x", - "@stdlib/ndarray-ctor": "^0.0.x", - "@stdlib/ndarray-ind2sub": "^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", @@ -85,9 +29,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..d691371 --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 7e8e63f..0000000 --- a/test/test.js +++ /dev/null @@ -1,514 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 array = require( '@stdlib/ndarray-array' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var maybeBroadcastArray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof maybeBroadcastArray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a desired shape which has fewer dimensions than the input array', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 ] - }); - - values = [ - [], - [ 2 ], - [ 2, 2 ], - [ 2, 2, 2 ], - [ 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2, 2, 2 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided a shape with '+values[ i ].length+' dimension' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape having a dimension whose size is less than the corresponding dimension in the input array', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 10, 1 ], - [ 10, 10, 2 ], - [ 10, 10, 9 ], - [ 10, 1, 10 ], - [ 10, 2, 10 ], - [ 10, 9, 10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape and an input array shape which are broadcast-incompatible', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 20, 10 ], - [ 10, 10, 100 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function returns a "base" ndarray instance', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = maybeBroadcastArray( x, [ 2, 2, 2 ] ); - - t.notEqual( y, x, 'returns new instance' ); - t.strictEqual( y instanceof ndarray, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view over the input array data buffer', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = maybeBroadcastArray( x, [ 2, 2, 2 ] ); - - t.strictEqual( y.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; strides)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, -1 ], 3, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; strides)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, 1 ], 2, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; non-contiguous)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ 4, 2 ], 1, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 5 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 7 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (column-major)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'column-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (same shape)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2, 2 ], - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - // Should return the same instance: - t.strictEqual( y, x, 'returns expected value' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 1, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 1, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (same number of dimensions)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1, 2 ], - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (singleton dimension)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (singleton dimension)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 1, 2 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (0-dimensional array)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1 ]; - x = ndarray( 'generic', data, [], [ 0 ], 0, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); From a3e32163ded5ca16f81ffb929a213dc167c0ee13 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Aug 2022 03:53:16 +0000 Subject: [PATCH 011/119] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index f2a827c..6083467 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ }, "dependencies": { "@stdlib/ndarray-base-broadcast-array": "^0.0.x", - "@stdlib/types": "^0.0.x" + "@stdlib/types": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x" }, "devDependencies": { "@stdlib/array-float64": "^0.0.x", @@ -89,4 +90,4 @@ "type": "patreon", "url": "https://www.patreon.com/athan" } -} +} \ No newline at end of file From 6ecb79019b609b7d0cda2a0971882de7ab8a43c5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Aug 2022 11:18:16 +0000 Subject: [PATCH 012/119] Remove files --- index.d.ts | 81 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2775 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index c60cbe5..0000000 --- a/index.d.ts +++ /dev/null @@ -1,81 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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'; -import { ndarray } from '@stdlib/types/ndarray'; - -/** -* Broadcasts an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* ## Notes -* -* - The function throws an error if a provided ndarray is incompatible with a provided shape. -* - If a provided ndarray has the same shape as the specified shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the specified shape, the function returns a new (base) ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to the view may affect multiple elements. If you need to write to the returned array, copy the array before performing operations which may mutate elements. -* - A returned array view is a "base" ndarray, and, thus, a returned array view does not perform bounds checking or afford any of the guarantees of the non-base ndarray constructor. The primary intent of this function is to broadcast an ndarray-like object within internal implementations and to do so with minimal overhead. -* -* @param arr - input array -* @param shape - desired shape -* @throws input array cannot have more dimensions than the desired shape -* @throws input array dimension sizes must be `1` or equal to the corresponding dimension in the provided shape -* @throws input array and desired shape must be broadcast compatible -* @returns broadcasted array -* -* @example -* var array = require( `@stdlib/ndarray/array` ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -*/ -declare function maybeBroadcastArray( arr: ndarray, shape: ArrayLike ): ndarray; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = maybeBroadcastArray; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index eeac6bf..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@esm/index.mjs";function t(t,e){var a,n,s;if(n=e.length,(a=t.shape).length===n){for(s=0;s\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import array from '@stdlib/ndarray-array' ;\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = arr.shape;\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArray;\n"],"names":["maybeBroadcastArray","arr","shape","sh","N","i","length","broadcast"],"mappings":";;gGAoFA,SAASA,EAAqBC,EAAKC,GAClC,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAMI,QACVH,EAAKF,EAAIC,OAGDI,SAAWF,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,KAAQH,EAAOG,GAEvB,OAAOE,EAAWN,EAAKC,GAGzB,OAAOD,EAGR,OAAOM,EAAWN,EAAKC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index d691371..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 1aad577e56fb54a38ae8684f7d20df4ef54394e8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Aug 2022 11:19:06 +0000 Subject: [PATCH 013/119] 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 | 47 +- benchmark/benchmark.js | 290 --- benchmark/benchmark.ndims.js | 110 - branches.md | 53 - docs/repl.txt | 74 - docs/types/test.ts | 94 - examples/index.js | 45 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 68 - lib/main.js | 111 - package.json | 63 +- stats.html | 2689 +++++++++++++++++++++ test/test.js | 514 ---- 38 files changed, 2718 insertions(+), 4335 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/benchmark.ndims.js delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (97%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/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 093bbb6..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-08-01T01:34:58.164Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 740d5ce..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/maybe-broadcast-array) 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 3740889..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/maybe-broadcast-array) 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 + + ```
@@ -160,7 +153,7 @@ for ( i = 0; i < N; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -220,11 +213,11 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-maybe-broadcast-array/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor +[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor/tree/esm -[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes +[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 9763740..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,290 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var ndarrayBase = require( '@stdlib/ndarray-base-ctor' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArray = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::base_ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::base_ndarray,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( out.shape[ 0 ] !== shape[ 0 ] ) { - b.fail( 'unexpected result' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.ndims.js b/benchmark/benchmark.ndims.js deleted file mode 100644 index 1fa371b..0000000 --- a/benchmark/benchmark.ndims.js +++ /dev/null @@ -1,110 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var array = require( '@stdlib/ndarray-array' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} ndims - number of dimensions to which to broadcast -* @returns {Function} benchmark function -*/ -function createBenchmark( ndims ) { - var shape; - var sh; - var x; - var i; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - sh = x.shape; - - shape = []; - for ( i = 0; i < ndims; i++ ) { - shape.push( 0 ); - } - for ( i = ndims; i >= 1; i-- ) { - if ( i > shape.length ) { - shape[ ndims-i ] = 5; - } else { - shape[ ndims-i ] = sh[ i-1 ]; - } - } - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( x, shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var min; - var max; - var f; - var i; - - min = 2; - max = 10; - - for ( i = min; i <= max; i++ ) { - f = createBenchmark( i ); - bench( pkg+'::ndarray,2d:from_ndims=2,to_ndims='+i, f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index b75f357..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/maybe-broadcast-array" -click B href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/main" -click C href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/production" -click D href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/maybe-broadcast-array -[production-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 93528fb..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,74 +0,0 @@ - -{{alias}}( arr, shape ) - Broadcasts an ndarray to a specified shape if and only if the specified - shape differs from the provided ndarray's shape. - - If a provided ndarray has the same shape as the specified shape, the - function returns the provided ndarray. - - If a provided ndarray has a different (broadcast compatible) shape than the - specified shape, the function returns a new (base) ndarray view of the - provided ndarray's data. The view is typically **not** contiguous. As more - than one element of a returned view may refer to the same memory location, - writing to the view may affect multiple elements. If you need to write to - the returned array, copy the array before performing operations which may - mutate elements. - - A returned array is a view on the input array data buffer. The view is - typically *not* contiguous. As more than one element of a returned view may - refer to the same memory location, writing to the view may affect multiple - elements. If you need to write to the returned array, copy the array before - performing operations which may mutate elements. - - A returned array view is a "base" ndarray, and, thus, a returned array view - does not perform bounds checking or afford any of the guarantees of the non- - base ndarray constructor. The primary intent of this function is to - broadcast an ndarray-like object within internal implementations and to do - so with minimal overhead. - - The function throws an error if a provided ndarray is incompatible with a - provided shape. - - Parameters - ---------- - arr: ndarray - Input array. - - shape: ArrayLikeObject - Desired shape. - - Returns - ------- - out: ndarray - Broadcasted array. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > var sh = x.shape - [ 2, 2 ] - > var y = {{alias}}( x, [ 3, 2, 2 ] ) - - > sh = y.shape - [ 3, 2, 2 ] - > var v = y.get( 0, 0, 0 ) - 1 - > v = y.get( 0, 0, 1 ) - 2 - > v = y.get( 0, 1, 0 ) - 3 - > v = y.get( 0, 1, 1 ) - 4 - > v = y.get( 1, 0, 0 ) - 1 - > v = y.get( 1, 1, 0 ) - 3 - > v = y.get( 2, 0, 0 ) - 1 - > v = y.get( 2, 1, 1 ) - 4 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index d7a1a62..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,94 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ndarray } from '@stdlib/types/ndarray'; -import maybeBroadcastArray = require( './index' ); - -/** -* Mock function to create an ndarray-like object. -* -* @return ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns an ndarray... -{ - const x = array(); - - maybeBroadcastArray( x, [ 2, 2, 2 ] ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is not provided a first argument which is an ndarray... -{ - maybeBroadcastArray( '5', [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( 5, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( true, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( false, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( null, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( {}, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( [ '5' ], [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( ( x: number ): number => x, [ 2, 2, 2 ] ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a second argument which is an array-like object containing numbers... -{ - const x = array(); - - maybeBroadcastArray( x, '5' ); // $ExpectError - maybeBroadcastArray( x, 5 ); // $ExpectError - maybeBroadcastArray( x, true ); // $ExpectError - maybeBroadcastArray( x, false ); // $ExpectError - maybeBroadcastArray( x, null ); // $ExpectError - maybeBroadcastArray( x, {} ); // $ExpectError - maybeBroadcastArray( x, [ '5' ] ); // $ExpectError - maybeBroadcastArray( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - - maybeBroadcastArray(); // $ExpectError - maybeBroadcastArray( x ); // $ExpectError - maybeBroadcastArray( x, [ 1, 2, 3 ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index e787d6e..0000000 --- a/examples/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 array = require( '@stdlib/ndarray-array' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var maybeBroadcastArray = require( './../lib' ); - -// Create a 2x2 array: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -// returns - -// Broadcast the array to 3x2x2: -var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -// returns - -// Retrieve the shape: -var sh = y.shape; -// returns [ 3, 2, 2 ] - -// Retrieve the number of elements: -var N = numel( sh ); - -// Loop through the array elements... -var i; -for ( i = 0; i < N; i++ ) { - console.log( 'Y[%s] = %d', ind2sub( sh, i ).join( ', ' ), y.iget( i ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 97% rename from docs/types/index.d.ts rename to index.d.ts index 6c11bdd..c60cbe5 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..eeac6bf --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@esm/index.mjs";function t(t,e){var a,n,s;if(n=e.length,(a=t.shape).length===n){for(s=0;s\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import array from '@stdlib/ndarray-array' ;\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = arr.shape;\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArray;\n"],"names":["maybeBroadcastArray","arr","shape","sh","N","i","length","broadcast"],"mappings":";;gGAoFA,SAASA,EAAqBC,EAAKC,GAClC,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAMI,QACVH,EAAKF,EAAIC,OAGDI,SAAWF,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,KAAQH,EAAOG,GAEvB,OAAOE,EAAWN,EAAKC,GAGzB,OAAOD,EAGR,OAAOM,EAAWN,EAAKC"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 834e930..0000000 --- a/lib/index.js +++ /dev/null @@ -1,68 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* @module @stdlib/ndarray-base-maybe-broadcast-array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var maybeBroadcastArray = require( '@stdlib/ndarray-base-maybe-broadcast-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -*/ - -// 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 278f868..0000000 --- a/lib/main.js +++ /dev/null @@ -1,111 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var broadcast = require( '@stdlib/ndarray-base-broadcast-array' ); - - -// MAIN // - -/** -* Broadcasts an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* ## Notes -* -* - If a provided ndarray has the same shape as the specified shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the specified shape, the function returns a new (base) ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to the view may affect multiple elements. If you need to write to the returned array, copy the array before performing operations which may mutate elements. -* -* @param {ndarray} arr - input array -* @param {NonNegativeIntegerArray} shape - desired shape -* @throws {Error} input array cannot have more dimensions than the desired shape -* @throws {Error} input array dimension sizes must be `1` or equal to the corresponding dimension in the provided shape -* @throws {Error} input array and desired shape must be broadcast compatible -* @returns {ndarray} broadcasted array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var y = maybeBroadcastArray( x, [ 3, 2 ] ); -* // throws -*/ -function maybeBroadcastArray( arr, shape ) { - var sh; - var N; - var i; - - N = shape.length; - sh = arr.shape; - - // Check whether we need to broadcast the input array... - if ( sh.length === N ) { - for ( i = 0; i < N; i++ ) { - // Check whether dimensions match... - if ( sh[ i ] !== shape[ i ] ) { - // We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape... - return broadcast( arr, shape ); - } - } - return arr; - } - // If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape... - return broadcast( arr, shape ); -} - - -// EXPORTS // - -module.exports = maybeBroadcastArray; diff --git a/package.json b/package.json index 6083467..97dd5d7 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.1", "description": "Broadcast an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's 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", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,39 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-base-broadcast-array": "^0.0.x", - "@stdlib/types": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.0.x", - "@stdlib/assert-is-ndarray-like": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/ndarray-array": "^0.0.x", - "@stdlib/ndarray-base-ctor": "^0.0.x", - "@stdlib/ndarray-base-numel": "^0.0.x", - "@stdlib/ndarray-ctor": "^0.0.x", - "@stdlib/ndarray-ind2sub": "^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", @@ -85,9 +29,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..21e053f --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 7e8e63f..0000000 --- a/test/test.js +++ /dev/null @@ -1,514 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 array = require( '@stdlib/ndarray-array' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var maybeBroadcastArray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof maybeBroadcastArray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a desired shape which has fewer dimensions than the input array', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 ] - }); - - values = [ - [], - [ 2 ], - [ 2, 2 ], - [ 2, 2, 2 ], - [ 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2, 2, 2 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided a shape with '+values[ i ].length+' dimension' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape having a dimension whose size is less than the corresponding dimension in the input array', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 10, 1 ], - [ 10, 10, 2 ], - [ 10, 10, 9 ], - [ 10, 1, 10 ], - [ 10, 2, 10 ], - [ 10, 9, 10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape and an input array shape which are broadcast-incompatible', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 20, 10 ], - [ 10, 10, 100 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function returns a "base" ndarray instance', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = maybeBroadcastArray( x, [ 2, 2, 2 ] ); - - t.notEqual( y, x, 'returns new instance' ); - t.strictEqual( y instanceof ndarray, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view over the input array data buffer', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = maybeBroadcastArray( x, [ 2, 2, 2 ] ); - - t.strictEqual( y.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; strides)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, -1 ], 3, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; strides)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, 1 ], 2, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; non-contiguous)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ 4, 2 ], 1, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 5 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 7 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (column-major)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'column-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (same shape)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2, 2 ], - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - // Should return the same instance: - t.strictEqual( y, x, 'returns expected value' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 1, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 1, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (same number of dimensions)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1, 2 ], - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (singleton dimension)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (singleton dimension)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 1, 2 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (0-dimensional array)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1 ]; - x = ndarray( 'generic', data, [], [ 0 ], 0, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); From 51583396c717205b422e6b2a728f1dd743391107 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Sep 2022 03:44:43 +0000 Subject: [PATCH 014/119] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index f2a827c..6083467 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ }, "dependencies": { "@stdlib/ndarray-base-broadcast-array": "^0.0.x", - "@stdlib/types": "^0.0.x" + "@stdlib/types": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x" }, "devDependencies": { "@stdlib/array-float64": "^0.0.x", @@ -89,4 +90,4 @@ "type": "patreon", "url": "https://www.patreon.com/athan" } -} +} \ No newline at end of file From 833d48477dfe233e39f20529cb8fcc9bd140b4c6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Sep 2022 14:02:18 +0000 Subject: [PATCH 015/119] Remove files --- index.d.ts | 81 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2775 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index c60cbe5..0000000 --- a/index.d.ts +++ /dev/null @@ -1,81 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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'; -import { ndarray } from '@stdlib/types/ndarray'; - -/** -* Broadcasts an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* ## Notes -* -* - The function throws an error if a provided ndarray is incompatible with a provided shape. -* - If a provided ndarray has the same shape as the specified shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the specified shape, the function returns a new (base) ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to the view may affect multiple elements. If you need to write to the returned array, copy the array before performing operations which may mutate elements. -* - A returned array view is a "base" ndarray, and, thus, a returned array view does not perform bounds checking or afford any of the guarantees of the non-base ndarray constructor. The primary intent of this function is to broadcast an ndarray-like object within internal implementations and to do so with minimal overhead. -* -* @param arr - input array -* @param shape - desired shape -* @throws input array cannot have more dimensions than the desired shape -* @throws input array dimension sizes must be `1` or equal to the corresponding dimension in the provided shape -* @throws input array and desired shape must be broadcast compatible -* @returns broadcasted array -* -* @example -* var array = require( `@stdlib/ndarray/array` ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -*/ -declare function maybeBroadcastArray( arr: ndarray, shape: ArrayLike ): ndarray; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = maybeBroadcastArray; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index eeac6bf..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@esm/index.mjs";function t(t,e){var a,n,s;if(n=e.length,(a=t.shape).length===n){for(s=0;s\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import array from '@stdlib/ndarray-array' ;\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = arr.shape;\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArray;\n"],"names":["maybeBroadcastArray","arr","shape","sh","N","i","length","broadcast"],"mappings":";;gGAoFA,SAASA,EAAqBC,EAAKC,GAClC,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAMI,QACVH,EAAKF,EAAIC,OAGDI,SAAWF,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,KAAQH,EAAOG,GAEvB,OAAOE,EAAWN,EAAKC,GAGzB,OAAOD,EAGR,OAAOM,EAAWN,EAAKC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 21e053f..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 0cb927fb2e13ea7d01d62b5fbcdc233abb41a957 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Sep 2022 14:03:27 +0000 Subject: [PATCH 016/119] 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 | 47 +- benchmark/benchmark.js | 290 --- benchmark/benchmark.ndims.js | 110 - branches.md | 53 - docs/repl.txt | 74 - docs/types/test.ts | 94 - examples/index.js | 45 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 68 - lib/main.js | 111 - package.json | 63 +- stats.html | 2689 +++++++++++++++++++++ test/test.js | 514 ---- 38 files changed, 2718 insertions(+), 4351 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/benchmark.ndims.js delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (97%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/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 9bddec6..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-09-01T01:34:12.328Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 740d5ce..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/maybe-broadcast-array) 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 3740889..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/maybe-broadcast-array) 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 + + ```
@@ -160,7 +153,7 @@ for ( i = 0; i < N; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -220,11 +213,11 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-maybe-broadcast-array/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor +[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor/tree/esm -[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes +[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 9763740..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,290 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var ndarrayBase = require( '@stdlib/ndarray-base-ctor' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArray = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::base_ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::base_ndarray,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( out.shape[ 0 ] !== shape[ 0 ] ) { - b.fail( 'unexpected result' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.ndims.js b/benchmark/benchmark.ndims.js deleted file mode 100644 index 1fa371b..0000000 --- a/benchmark/benchmark.ndims.js +++ /dev/null @@ -1,110 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var array = require( '@stdlib/ndarray-array' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} ndims - number of dimensions to which to broadcast -* @returns {Function} benchmark function -*/ -function createBenchmark( ndims ) { - var shape; - var sh; - var x; - var i; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - sh = x.shape; - - shape = []; - for ( i = 0; i < ndims; i++ ) { - shape.push( 0 ); - } - for ( i = ndims; i >= 1; i-- ) { - if ( i > shape.length ) { - shape[ ndims-i ] = 5; - } else { - shape[ ndims-i ] = sh[ i-1 ]; - } - } - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( x, shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var min; - var max; - var f; - var i; - - min = 2; - max = 10; - - for ( i = min; i <= max; i++ ) { - f = createBenchmark( i ); - bench( pkg+'::ndarray,2d:from_ndims=2,to_ndims='+i, f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index b75f357..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/maybe-broadcast-array" -click B href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/main" -click C href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/production" -click D href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/maybe-broadcast-array -[production-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 93528fb..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,74 +0,0 @@ - -{{alias}}( arr, shape ) - Broadcasts an ndarray to a specified shape if and only if the specified - shape differs from the provided ndarray's shape. - - If a provided ndarray has the same shape as the specified shape, the - function returns the provided ndarray. - - If a provided ndarray has a different (broadcast compatible) shape than the - specified shape, the function returns a new (base) ndarray view of the - provided ndarray's data. The view is typically **not** contiguous. As more - than one element of a returned view may refer to the same memory location, - writing to the view may affect multiple elements. If you need to write to - the returned array, copy the array before performing operations which may - mutate elements. - - A returned array is a view on the input array data buffer. The view is - typically *not* contiguous. As more than one element of a returned view may - refer to the same memory location, writing to the view may affect multiple - elements. If you need to write to the returned array, copy the array before - performing operations which may mutate elements. - - A returned array view is a "base" ndarray, and, thus, a returned array view - does not perform bounds checking or afford any of the guarantees of the non- - base ndarray constructor. The primary intent of this function is to - broadcast an ndarray-like object within internal implementations and to do - so with minimal overhead. - - The function throws an error if a provided ndarray is incompatible with a - provided shape. - - Parameters - ---------- - arr: ndarray - Input array. - - shape: ArrayLikeObject - Desired shape. - - Returns - ------- - out: ndarray - Broadcasted array. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > var sh = x.shape - [ 2, 2 ] - > var y = {{alias}}( x, [ 3, 2, 2 ] ) - - > sh = y.shape - [ 3, 2, 2 ] - > var v = y.get( 0, 0, 0 ) - 1 - > v = y.get( 0, 0, 1 ) - 2 - > v = y.get( 0, 1, 0 ) - 3 - > v = y.get( 0, 1, 1 ) - 4 - > v = y.get( 1, 0, 0 ) - 1 - > v = y.get( 1, 1, 0 ) - 3 - > v = y.get( 2, 0, 0 ) - 1 - > v = y.get( 2, 1, 1 ) - 4 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index d7a1a62..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,94 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ndarray } from '@stdlib/types/ndarray'; -import maybeBroadcastArray = require( './index' ); - -/** -* Mock function to create an ndarray-like object. -* -* @return ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns an ndarray... -{ - const x = array(); - - maybeBroadcastArray( x, [ 2, 2, 2 ] ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is not provided a first argument which is an ndarray... -{ - maybeBroadcastArray( '5', [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( 5, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( true, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( false, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( null, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( {}, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( [ '5' ], [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( ( x: number ): number => x, [ 2, 2, 2 ] ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a second argument which is an array-like object containing numbers... -{ - const x = array(); - - maybeBroadcastArray( x, '5' ); // $ExpectError - maybeBroadcastArray( x, 5 ); // $ExpectError - maybeBroadcastArray( x, true ); // $ExpectError - maybeBroadcastArray( x, false ); // $ExpectError - maybeBroadcastArray( x, null ); // $ExpectError - maybeBroadcastArray( x, {} ); // $ExpectError - maybeBroadcastArray( x, [ '5' ] ); // $ExpectError - maybeBroadcastArray( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - - maybeBroadcastArray(); // $ExpectError - maybeBroadcastArray( x ); // $ExpectError - maybeBroadcastArray( x, [ 1, 2, 3 ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index e787d6e..0000000 --- a/examples/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 array = require( '@stdlib/ndarray-array' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var maybeBroadcastArray = require( './../lib' ); - -// Create a 2x2 array: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -// returns - -// Broadcast the array to 3x2x2: -var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -// returns - -// Retrieve the shape: -var sh = y.shape; -// returns [ 3, 2, 2 ] - -// Retrieve the number of elements: -var N = numel( sh ); - -// Loop through the array elements... -var i; -for ( i = 0; i < N; i++ ) { - console.log( 'Y[%s] = %d', ind2sub( sh, i ).join( ', ' ), y.iget( i ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 97% rename from docs/types/index.d.ts rename to index.d.ts index 6c11bdd..c60cbe5 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..eeac6bf --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@esm/index.mjs";function t(t,e){var a,n,s;if(n=e.length,(a=t.shape).length===n){for(s=0;s\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import array from '@stdlib/ndarray-array' ;\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = arr.shape;\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArray;\n"],"names":["maybeBroadcastArray","arr","shape","sh","N","i","length","broadcast"],"mappings":";;gGAoFA,SAASA,EAAqBC,EAAKC,GAClC,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAMI,QACVH,EAAKF,EAAIC,OAGDI,SAAWF,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,KAAQH,EAAOG,GAEvB,OAAOE,EAAWN,EAAKC,GAGzB,OAAOD,EAGR,OAAOM,EAAWN,EAAKC"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 834e930..0000000 --- a/lib/index.js +++ /dev/null @@ -1,68 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* @module @stdlib/ndarray-base-maybe-broadcast-array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var maybeBroadcastArray = require( '@stdlib/ndarray-base-maybe-broadcast-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -*/ - -// 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 278f868..0000000 --- a/lib/main.js +++ /dev/null @@ -1,111 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var broadcast = require( '@stdlib/ndarray-base-broadcast-array' ); - - -// MAIN // - -/** -* Broadcasts an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* ## Notes -* -* - If a provided ndarray has the same shape as the specified shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the specified shape, the function returns a new (base) ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to the view may affect multiple elements. If you need to write to the returned array, copy the array before performing operations which may mutate elements. -* -* @param {ndarray} arr - input array -* @param {NonNegativeIntegerArray} shape - desired shape -* @throws {Error} input array cannot have more dimensions than the desired shape -* @throws {Error} input array dimension sizes must be `1` or equal to the corresponding dimension in the provided shape -* @throws {Error} input array and desired shape must be broadcast compatible -* @returns {ndarray} broadcasted array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var y = maybeBroadcastArray( x, [ 3, 2 ] ); -* // throws -*/ -function maybeBroadcastArray( arr, shape ) { - var sh; - var N; - var i; - - N = shape.length; - sh = arr.shape; - - // Check whether we need to broadcast the input array... - if ( sh.length === N ) { - for ( i = 0; i < N; i++ ) { - // Check whether dimensions match... - if ( sh[ i ] !== shape[ i ] ) { - // We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape... - return broadcast( arr, shape ); - } - } - return arr; - } - // If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape... - return broadcast( arr, shape ); -} - - -// EXPORTS // - -module.exports = maybeBroadcastArray; diff --git a/package.json b/package.json index 6083467..97dd5d7 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.1", "description": "Broadcast an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's 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", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,39 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-base-broadcast-array": "^0.0.x", - "@stdlib/types": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.0.x", - "@stdlib/assert-is-ndarray-like": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/ndarray-array": "^0.0.x", - "@stdlib/ndarray-base-ctor": "^0.0.x", - "@stdlib/ndarray-base-numel": "^0.0.x", - "@stdlib/ndarray-ctor": "^0.0.x", - "@stdlib/ndarray-ind2sub": "^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", @@ -85,9 +29,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..3ccc9b6 --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 7e8e63f..0000000 --- a/test/test.js +++ /dev/null @@ -1,514 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 array = require( '@stdlib/ndarray-array' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var maybeBroadcastArray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof maybeBroadcastArray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a desired shape which has fewer dimensions than the input array', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 ] - }); - - values = [ - [], - [ 2 ], - [ 2, 2 ], - [ 2, 2, 2 ], - [ 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2, 2, 2 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided a shape with '+values[ i ].length+' dimension' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape having a dimension whose size is less than the corresponding dimension in the input array', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 10, 1 ], - [ 10, 10, 2 ], - [ 10, 10, 9 ], - [ 10, 1, 10 ], - [ 10, 2, 10 ], - [ 10, 9, 10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape and an input array shape which are broadcast-incompatible', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 20, 10 ], - [ 10, 10, 100 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function returns a "base" ndarray instance', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = maybeBroadcastArray( x, [ 2, 2, 2 ] ); - - t.notEqual( y, x, 'returns new instance' ); - t.strictEqual( y instanceof ndarray, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view over the input array data buffer', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = maybeBroadcastArray( x, [ 2, 2, 2 ] ); - - t.strictEqual( y.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; strides)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, -1 ], 3, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; strides)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, 1 ], 2, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; non-contiguous)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ 4, 2 ], 1, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 5 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 7 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (column-major)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'column-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (same shape)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2, 2 ], - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - // Should return the same instance: - t.strictEqual( y, x, 'returns expected value' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 1, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 1, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (same number of dimensions)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1, 2 ], - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (singleton dimension)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (singleton dimension)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 1, 2 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (0-dimensional array)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1 ]; - x = ndarray( 'generic', data, [], [ 0 ], 0, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); From a06ce39c21e7a0b1adb196692c829746d0fcc405 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Oct 2022 04:12:30 +0000 Subject: [PATCH 017/119] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index f2a827c..6083467 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ }, "dependencies": { "@stdlib/ndarray-base-broadcast-array": "^0.0.x", - "@stdlib/types": "^0.0.x" + "@stdlib/types": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x" }, "devDependencies": { "@stdlib/array-float64": "^0.0.x", @@ -89,4 +90,4 @@ "type": "patreon", "url": "https://www.patreon.com/athan" } -} +} \ No newline at end of file From 4d820ce52f5721fe7e75ab1968ea7b37713bd695 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Oct 2022 15:43:57 +0000 Subject: [PATCH 018/119] Remove files --- index.d.ts | 81 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2775 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index c60cbe5..0000000 --- a/index.d.ts +++ /dev/null @@ -1,81 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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'; -import { ndarray } from '@stdlib/types/ndarray'; - -/** -* Broadcasts an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* ## Notes -* -* - The function throws an error if a provided ndarray is incompatible with a provided shape. -* - If a provided ndarray has the same shape as the specified shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the specified shape, the function returns a new (base) ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to the view may affect multiple elements. If you need to write to the returned array, copy the array before performing operations which may mutate elements. -* - A returned array view is a "base" ndarray, and, thus, a returned array view does not perform bounds checking or afford any of the guarantees of the non-base ndarray constructor. The primary intent of this function is to broadcast an ndarray-like object within internal implementations and to do so with minimal overhead. -* -* @param arr - input array -* @param shape - desired shape -* @throws input array cannot have more dimensions than the desired shape -* @throws input array dimension sizes must be `1` or equal to the corresponding dimension in the provided shape -* @throws input array and desired shape must be broadcast compatible -* @returns broadcasted array -* -* @example -* var array = require( `@stdlib/ndarray/array` ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -*/ -declare function maybeBroadcastArray( arr: ndarray, shape: ArrayLike ): ndarray; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = maybeBroadcastArray; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index eeac6bf..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@esm/index.mjs";function t(t,e){var a,n,s;if(n=e.length,(a=t.shape).length===n){for(s=0;s\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import array from '@stdlib/ndarray-array' ;\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = arr.shape;\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArray;\n"],"names":["maybeBroadcastArray","arr","shape","sh","N","i","length","broadcast"],"mappings":";;gGAoFA,SAASA,EAAqBC,EAAKC,GAClC,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAMI,QACVH,EAAKF,EAAIC,OAGDI,SAAWF,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,KAAQH,EAAOG,GAEvB,OAAOE,EAAWN,EAAKC,GAGzB,OAAOD,EAGR,OAAOM,EAAWN,EAAKC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 3ccc9b6..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 7359b2bb4a083be270d4ca39ef1b762e4c82f5ab Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Oct 2022 15:44:46 +0000 Subject: [PATCH 019/119] 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 | 47 +- benchmark/benchmark.js | 290 --- benchmark/benchmark.ndims.js | 110 - branches.md | 53 - docs/repl.txt | 74 - docs/types/test.ts | 94 - examples/index.js | 45 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 68 - lib/main.js | 111 - package.json | 63 +- stats.html | 2689 +++++++++++++++++++++ test/test.js | 514 ---- 38 files changed, 2718 insertions(+), 4351 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/benchmark.ndims.js delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (97%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/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 62f1612..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-10-01T02:01:15.515Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 740d5ce..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/maybe-broadcast-array) 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 3740889..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/maybe-broadcast-array) 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 + + ```
@@ -160,7 +153,7 @@ for ( i = 0; i < N; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -220,11 +213,11 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-maybe-broadcast-array/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor +[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor/tree/esm -[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes +[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 9763740..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,290 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var ndarrayBase = require( '@stdlib/ndarray-base-ctor' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArray = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::base_ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::base_ndarray,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( out.shape[ 0 ] !== shape[ 0 ] ) { - b.fail( 'unexpected result' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.ndims.js b/benchmark/benchmark.ndims.js deleted file mode 100644 index 1fa371b..0000000 --- a/benchmark/benchmark.ndims.js +++ /dev/null @@ -1,110 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var array = require( '@stdlib/ndarray-array' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} ndims - number of dimensions to which to broadcast -* @returns {Function} benchmark function -*/ -function createBenchmark( ndims ) { - var shape; - var sh; - var x; - var i; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - sh = x.shape; - - shape = []; - for ( i = 0; i < ndims; i++ ) { - shape.push( 0 ); - } - for ( i = ndims; i >= 1; i-- ) { - if ( i > shape.length ) { - shape[ ndims-i ] = 5; - } else { - shape[ ndims-i ] = sh[ i-1 ]; - } - } - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( x, shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var min; - var max; - var f; - var i; - - min = 2; - max = 10; - - for ( i = min; i <= max; i++ ) { - f = createBenchmark( i ); - bench( pkg+'::ndarray,2d:from_ndims=2,to_ndims='+i, f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index b75f357..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/maybe-broadcast-array" -click B href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/main" -click C href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/production" -click D href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/maybe-broadcast-array -[production-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 93528fb..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,74 +0,0 @@ - -{{alias}}( arr, shape ) - Broadcasts an ndarray to a specified shape if and only if the specified - shape differs from the provided ndarray's shape. - - If a provided ndarray has the same shape as the specified shape, the - function returns the provided ndarray. - - If a provided ndarray has a different (broadcast compatible) shape than the - specified shape, the function returns a new (base) ndarray view of the - provided ndarray's data. The view is typically **not** contiguous. As more - than one element of a returned view may refer to the same memory location, - writing to the view may affect multiple elements. If you need to write to - the returned array, copy the array before performing operations which may - mutate elements. - - A returned array is a view on the input array data buffer. The view is - typically *not* contiguous. As more than one element of a returned view may - refer to the same memory location, writing to the view may affect multiple - elements. If you need to write to the returned array, copy the array before - performing operations which may mutate elements. - - A returned array view is a "base" ndarray, and, thus, a returned array view - does not perform bounds checking or afford any of the guarantees of the non- - base ndarray constructor. The primary intent of this function is to - broadcast an ndarray-like object within internal implementations and to do - so with minimal overhead. - - The function throws an error if a provided ndarray is incompatible with a - provided shape. - - Parameters - ---------- - arr: ndarray - Input array. - - shape: ArrayLikeObject - Desired shape. - - Returns - ------- - out: ndarray - Broadcasted array. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > var sh = x.shape - [ 2, 2 ] - > var y = {{alias}}( x, [ 3, 2, 2 ] ) - - > sh = y.shape - [ 3, 2, 2 ] - > var v = y.get( 0, 0, 0 ) - 1 - > v = y.get( 0, 0, 1 ) - 2 - > v = y.get( 0, 1, 0 ) - 3 - > v = y.get( 0, 1, 1 ) - 4 - > v = y.get( 1, 0, 0 ) - 1 - > v = y.get( 1, 1, 0 ) - 3 - > v = y.get( 2, 0, 0 ) - 1 - > v = y.get( 2, 1, 1 ) - 4 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index d7a1a62..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,94 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ndarray } from '@stdlib/types/ndarray'; -import maybeBroadcastArray = require( './index' ); - -/** -* Mock function to create an ndarray-like object. -* -* @return ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns an ndarray... -{ - const x = array(); - - maybeBroadcastArray( x, [ 2, 2, 2 ] ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is not provided a first argument which is an ndarray... -{ - maybeBroadcastArray( '5', [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( 5, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( true, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( false, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( null, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( {}, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( [ '5' ], [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( ( x: number ): number => x, [ 2, 2, 2 ] ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a second argument which is an array-like object containing numbers... -{ - const x = array(); - - maybeBroadcastArray( x, '5' ); // $ExpectError - maybeBroadcastArray( x, 5 ); // $ExpectError - maybeBroadcastArray( x, true ); // $ExpectError - maybeBroadcastArray( x, false ); // $ExpectError - maybeBroadcastArray( x, null ); // $ExpectError - maybeBroadcastArray( x, {} ); // $ExpectError - maybeBroadcastArray( x, [ '5' ] ); // $ExpectError - maybeBroadcastArray( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - - maybeBroadcastArray(); // $ExpectError - maybeBroadcastArray( x ); // $ExpectError - maybeBroadcastArray( x, [ 1, 2, 3 ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index e787d6e..0000000 --- a/examples/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 array = require( '@stdlib/ndarray-array' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var maybeBroadcastArray = require( './../lib' ); - -// Create a 2x2 array: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -// returns - -// Broadcast the array to 3x2x2: -var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -// returns - -// Retrieve the shape: -var sh = y.shape; -// returns [ 3, 2, 2 ] - -// Retrieve the number of elements: -var N = numel( sh ); - -// Loop through the array elements... -var i; -for ( i = 0; i < N; i++ ) { - console.log( 'Y[%s] = %d', ind2sub( sh, i ).join( ', ' ), y.iget( i ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 97% rename from docs/types/index.d.ts rename to index.d.ts index 6c11bdd..c60cbe5 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..eeac6bf --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@esm/index.mjs";function t(t,e){var a,n,s;if(n=e.length,(a=t.shape).length===n){for(s=0;s\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import array from '@stdlib/ndarray-array' ;\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = arr.shape;\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArray;\n"],"names":["maybeBroadcastArray","arr","shape","sh","N","i","length","broadcast"],"mappings":";;gGAoFA,SAASA,EAAqBC,EAAKC,GAClC,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAMI,QACVH,EAAKF,EAAIC,OAGDI,SAAWF,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,KAAQH,EAAOG,GAEvB,OAAOE,EAAWN,EAAKC,GAGzB,OAAOD,EAGR,OAAOM,EAAWN,EAAKC"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 834e930..0000000 --- a/lib/index.js +++ /dev/null @@ -1,68 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* @module @stdlib/ndarray-base-maybe-broadcast-array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var maybeBroadcastArray = require( '@stdlib/ndarray-base-maybe-broadcast-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -*/ - -// 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 278f868..0000000 --- a/lib/main.js +++ /dev/null @@ -1,111 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var broadcast = require( '@stdlib/ndarray-base-broadcast-array' ); - - -// MAIN // - -/** -* Broadcasts an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* ## Notes -* -* - If a provided ndarray has the same shape as the specified shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the specified shape, the function returns a new (base) ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to the view may affect multiple elements. If you need to write to the returned array, copy the array before performing operations which may mutate elements. -* -* @param {ndarray} arr - input array -* @param {NonNegativeIntegerArray} shape - desired shape -* @throws {Error} input array cannot have more dimensions than the desired shape -* @throws {Error} input array dimension sizes must be `1` or equal to the corresponding dimension in the provided shape -* @throws {Error} input array and desired shape must be broadcast compatible -* @returns {ndarray} broadcasted array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var y = maybeBroadcastArray( x, [ 3, 2 ] ); -* // throws -*/ -function maybeBroadcastArray( arr, shape ) { - var sh; - var N; - var i; - - N = shape.length; - sh = arr.shape; - - // Check whether we need to broadcast the input array... - if ( sh.length === N ) { - for ( i = 0; i < N; i++ ) { - // Check whether dimensions match... - if ( sh[ i ] !== shape[ i ] ) { - // We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape... - return broadcast( arr, shape ); - } - } - return arr; - } - // If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape... - return broadcast( arr, shape ); -} - - -// EXPORTS // - -module.exports = maybeBroadcastArray; diff --git a/package.json b/package.json index 6083467..97dd5d7 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.1", "description": "Broadcast an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's 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", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,39 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-base-broadcast-array": "^0.0.x", - "@stdlib/types": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.0.x", - "@stdlib/assert-is-ndarray-like": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/ndarray-array": "^0.0.x", - "@stdlib/ndarray-base-ctor": "^0.0.x", - "@stdlib/ndarray-base-numel": "^0.0.x", - "@stdlib/ndarray-ctor": "^0.0.x", - "@stdlib/ndarray-ind2sub": "^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", @@ -85,9 +29,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..9305bc8 --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 7e8e63f..0000000 --- a/test/test.js +++ /dev/null @@ -1,514 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 array = require( '@stdlib/ndarray-array' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var maybeBroadcastArray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof maybeBroadcastArray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a desired shape which has fewer dimensions than the input array', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 ] - }); - - values = [ - [], - [ 2 ], - [ 2, 2 ], - [ 2, 2, 2 ], - [ 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2, 2, 2 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided a shape with '+values[ i ].length+' dimension' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape having a dimension whose size is less than the corresponding dimension in the input array', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 10, 1 ], - [ 10, 10, 2 ], - [ 10, 10, 9 ], - [ 10, 1, 10 ], - [ 10, 2, 10 ], - [ 10, 9, 10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape and an input array shape which are broadcast-incompatible', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 20, 10 ], - [ 10, 10, 100 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function returns a "base" ndarray instance', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = maybeBroadcastArray( x, [ 2, 2, 2 ] ); - - t.notEqual( y, x, 'returns new instance' ); - t.strictEqual( y instanceof ndarray, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view over the input array data buffer', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = maybeBroadcastArray( x, [ 2, 2, 2 ] ); - - t.strictEqual( y.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; strides)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, -1 ], 3, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; strides)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, 1 ], 2, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; non-contiguous)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ 4, 2 ], 1, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 5 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 7 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (column-major)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'column-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (same shape)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2, 2 ], - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - // Should return the same instance: - t.strictEqual( y, x, 'returns expected value' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 1, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 1, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (same number of dimensions)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1, 2 ], - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (singleton dimension)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (singleton dimension)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 1, 2 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (0-dimensional array)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1 ]; - x = ndarray( 'generic', data, [], [ 0 ], 0, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); From 97e5aa27d3203813bcf7ca41d24c59b68339b007 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Nov 2022 01:51:05 +0000 Subject: [PATCH 020/119] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index f2a827c..6083467 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ }, "dependencies": { "@stdlib/ndarray-base-broadcast-array": "^0.0.x", - "@stdlib/types": "^0.0.x" + "@stdlib/types": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x" }, "devDependencies": { "@stdlib/array-float64": "^0.0.x", @@ -89,4 +90,4 @@ "type": "patreon", "url": "https://www.patreon.com/athan" } -} +} \ No newline at end of file From b08c973669c85df515849ed9f0c950f7c2b54200 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Nov 2022 18:06:03 +0000 Subject: [PATCH 021/119] Remove files --- index.d.ts | 81 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2775 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index c60cbe5..0000000 --- a/index.d.ts +++ /dev/null @@ -1,81 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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'; -import { ndarray } from '@stdlib/types/ndarray'; - -/** -* Broadcasts an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* ## Notes -* -* - The function throws an error if a provided ndarray is incompatible with a provided shape. -* - If a provided ndarray has the same shape as the specified shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the specified shape, the function returns a new (base) ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to the view may affect multiple elements. If you need to write to the returned array, copy the array before performing operations which may mutate elements. -* - A returned array view is a "base" ndarray, and, thus, a returned array view does not perform bounds checking or afford any of the guarantees of the non-base ndarray constructor. The primary intent of this function is to broadcast an ndarray-like object within internal implementations and to do so with minimal overhead. -* -* @param arr - input array -* @param shape - desired shape -* @throws input array cannot have more dimensions than the desired shape -* @throws input array dimension sizes must be `1` or equal to the corresponding dimension in the provided shape -* @throws input array and desired shape must be broadcast compatible -* @returns broadcasted array -* -* @example -* var array = require( `@stdlib/ndarray/array` ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -*/ -declare function maybeBroadcastArray( arr: ndarray, shape: ArrayLike ): ndarray; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = maybeBroadcastArray; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index eeac6bf..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@esm/index.mjs";function t(t,e){var a,n,s;if(n=e.length,(a=t.shape).length===n){for(s=0;s\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import array from '@stdlib/ndarray-array' ;\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = arr.shape;\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArray;\n"],"names":["maybeBroadcastArray","arr","shape","sh","N","i","length","broadcast"],"mappings":";;gGAoFA,SAASA,EAAqBC,EAAKC,GAClC,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAMI,QACVH,EAAKF,EAAIC,OAGDI,SAAWF,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,KAAQH,EAAOG,GAEvB,OAAOE,EAAWN,EAAKC,GAGzB,OAAOD,EAGR,OAAOM,EAAWN,EAAKC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 9305bc8..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 4129df8d6b2f4fd9c64edf6a0326140a1b487192 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Nov 2022 18:06:57 +0000 Subject: [PATCH 022/119] 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 | 47 +- benchmark/benchmark.js | 290 -- benchmark/benchmark.ndims.js | 110 - branches.md | 53 - docs/repl.txt | 74 - docs/types/test.ts | 94 - examples/index.js | 45 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 68 - lib/main.js | 111 - package.json | 63 +- stats.html | 4044 +++++++++++++++++++++ test/test.js | 514 --- 38 files changed, 4073 insertions(+), 4351 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/benchmark.ndims.js delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (97%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/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 5e6aa6c..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-11-01T01:47:29.286Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 740d5ce..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/maybe-broadcast-array) 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 3740889..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/maybe-broadcast-array) 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 f89b1b9..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: '45 9 * * 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 + + ```
@@ -160,7 +153,7 @@ for ( i = 0; i < N; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -220,11 +213,11 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-maybe-broadcast-array/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor +[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor/tree/esm -[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes +[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 9763740..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,290 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var ndarrayBase = require( '@stdlib/ndarray-base-ctor' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArray = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::base_ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::base_ndarray,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( out.shape[ 0 ] !== shape[ 0 ] ) { - b.fail( 'unexpected result' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.ndims.js b/benchmark/benchmark.ndims.js deleted file mode 100644 index 1fa371b..0000000 --- a/benchmark/benchmark.ndims.js +++ /dev/null @@ -1,110 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var array = require( '@stdlib/ndarray-array' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} ndims - number of dimensions to which to broadcast -* @returns {Function} benchmark function -*/ -function createBenchmark( ndims ) { - var shape; - var sh; - var x; - var i; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - sh = x.shape; - - shape = []; - for ( i = 0; i < ndims; i++ ) { - shape.push( 0 ); - } - for ( i = ndims; i >= 1; i-- ) { - if ( i > shape.length ) { - shape[ ndims-i ] = 5; - } else { - shape[ ndims-i ] = sh[ i-1 ]; - } - } - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( x, shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var min; - var max; - var f; - var i; - - min = 2; - max = 10; - - for ( i = min; i <= max; i++ ) { - f = createBenchmark( i ); - bench( pkg+'::ndarray,2d:from_ndims=2,to_ndims='+i, f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index b75f357..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/maybe-broadcast-array" -click B href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/main" -click C href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/production" -click D href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/maybe-broadcast-array -[production-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 93528fb..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,74 +0,0 @@ - -{{alias}}( arr, shape ) - Broadcasts an ndarray to a specified shape if and only if the specified - shape differs from the provided ndarray's shape. - - If a provided ndarray has the same shape as the specified shape, the - function returns the provided ndarray. - - If a provided ndarray has a different (broadcast compatible) shape than the - specified shape, the function returns a new (base) ndarray view of the - provided ndarray's data. The view is typically **not** contiguous. As more - than one element of a returned view may refer to the same memory location, - writing to the view may affect multiple elements. If you need to write to - the returned array, copy the array before performing operations which may - mutate elements. - - A returned array is a view on the input array data buffer. The view is - typically *not* contiguous. As more than one element of a returned view may - refer to the same memory location, writing to the view may affect multiple - elements. If you need to write to the returned array, copy the array before - performing operations which may mutate elements. - - A returned array view is a "base" ndarray, and, thus, a returned array view - does not perform bounds checking or afford any of the guarantees of the non- - base ndarray constructor. The primary intent of this function is to - broadcast an ndarray-like object within internal implementations and to do - so with minimal overhead. - - The function throws an error if a provided ndarray is incompatible with a - provided shape. - - Parameters - ---------- - arr: ndarray - Input array. - - shape: ArrayLikeObject - Desired shape. - - Returns - ------- - out: ndarray - Broadcasted array. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > var sh = x.shape - [ 2, 2 ] - > var y = {{alias}}( x, [ 3, 2, 2 ] ) - - > sh = y.shape - [ 3, 2, 2 ] - > var v = y.get( 0, 0, 0 ) - 1 - > v = y.get( 0, 0, 1 ) - 2 - > v = y.get( 0, 1, 0 ) - 3 - > v = y.get( 0, 1, 1 ) - 4 - > v = y.get( 1, 0, 0 ) - 1 - > v = y.get( 1, 1, 0 ) - 3 - > v = y.get( 2, 0, 0 ) - 1 - > v = y.get( 2, 1, 1 ) - 4 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index d7a1a62..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,94 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ndarray } from '@stdlib/types/ndarray'; -import maybeBroadcastArray = require( './index' ); - -/** -* Mock function to create an ndarray-like object. -* -* @return ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns an ndarray... -{ - const x = array(); - - maybeBroadcastArray( x, [ 2, 2, 2 ] ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is not provided a first argument which is an ndarray... -{ - maybeBroadcastArray( '5', [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( 5, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( true, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( false, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( null, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( {}, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( [ '5' ], [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( ( x: number ): number => x, [ 2, 2, 2 ] ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a second argument which is an array-like object containing numbers... -{ - const x = array(); - - maybeBroadcastArray( x, '5' ); // $ExpectError - maybeBroadcastArray( x, 5 ); // $ExpectError - maybeBroadcastArray( x, true ); // $ExpectError - maybeBroadcastArray( x, false ); // $ExpectError - maybeBroadcastArray( x, null ); // $ExpectError - maybeBroadcastArray( x, {} ); // $ExpectError - maybeBroadcastArray( x, [ '5' ] ); // $ExpectError - maybeBroadcastArray( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - - maybeBroadcastArray(); // $ExpectError - maybeBroadcastArray( x ); // $ExpectError - maybeBroadcastArray( x, [ 1, 2, 3 ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index e787d6e..0000000 --- a/examples/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 array = require( '@stdlib/ndarray-array' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var maybeBroadcastArray = require( './../lib' ); - -// Create a 2x2 array: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -// returns - -// Broadcast the array to 3x2x2: -var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -// returns - -// Retrieve the shape: -var sh = y.shape; -// returns [ 3, 2, 2 ] - -// Retrieve the number of elements: -var N = numel( sh ); - -// Loop through the array elements... -var i; -for ( i = 0; i < N; i++ ) { - console.log( 'Y[%s] = %d', ind2sub( sh, i ).join( ', ' ), y.iget( i ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 97% rename from docs/types/index.d.ts rename to index.d.ts index 6c11bdd..c60cbe5 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..eeac6bf --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@esm/index.mjs";function t(t,e){var a,n,s;if(n=e.length,(a=t.shape).length===n){for(s=0;s\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import array from '@stdlib/ndarray-array' ;\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = arr.shape;\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArray;\n"],"names":["maybeBroadcastArray","arr","shape","sh","N","i","length","broadcast"],"mappings":";;gGAoFA,SAASA,EAAqBC,EAAKC,GAClC,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAMI,QACVH,EAAKF,EAAIC,OAGDI,SAAWF,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,KAAQH,EAAOG,GAEvB,OAAOE,EAAWN,EAAKC,GAGzB,OAAOD,CACP,CAED,OAAOM,EAAWN,EAAKC,EACxB"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 834e930..0000000 --- a/lib/index.js +++ /dev/null @@ -1,68 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* @module @stdlib/ndarray-base-maybe-broadcast-array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var maybeBroadcastArray = require( '@stdlib/ndarray-base-maybe-broadcast-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -*/ - -// 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 278f868..0000000 --- a/lib/main.js +++ /dev/null @@ -1,111 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var broadcast = require( '@stdlib/ndarray-base-broadcast-array' ); - - -// MAIN // - -/** -* Broadcasts an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* ## Notes -* -* - If a provided ndarray has the same shape as the specified shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the specified shape, the function returns a new (base) ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to the view may affect multiple elements. If you need to write to the returned array, copy the array before performing operations which may mutate elements. -* -* @param {ndarray} arr - input array -* @param {NonNegativeIntegerArray} shape - desired shape -* @throws {Error} input array cannot have more dimensions than the desired shape -* @throws {Error} input array dimension sizes must be `1` or equal to the corresponding dimension in the provided shape -* @throws {Error} input array and desired shape must be broadcast compatible -* @returns {ndarray} broadcasted array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var y = maybeBroadcastArray( x, [ 3, 2 ] ); -* // throws -*/ -function maybeBroadcastArray( arr, shape ) { - var sh; - var N; - var i; - - N = shape.length; - sh = arr.shape; - - // Check whether we need to broadcast the input array... - if ( sh.length === N ) { - for ( i = 0; i < N; i++ ) { - // Check whether dimensions match... - if ( sh[ i ] !== shape[ i ] ) { - // We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape... - return broadcast( arr, shape ); - } - } - return arr; - } - // If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape... - return broadcast( arr, shape ); -} - - -// EXPORTS // - -module.exports = maybeBroadcastArray; diff --git a/package.json b/package.json index 6083467..97dd5d7 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.1", "description": "Broadcast an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's 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", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,39 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-base-broadcast-array": "^0.0.x", - "@stdlib/types": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.0.x", - "@stdlib/assert-is-ndarray-like": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/ndarray-array": "^0.0.x", - "@stdlib/ndarray-base-ctor": "^0.0.x", - "@stdlib/ndarray-base-numel": "^0.0.x", - "@stdlib/ndarray-ctor": "^0.0.x", - "@stdlib/ndarray-ind2sub": "^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", @@ -85,9 +29,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..1c4063b --- /dev/null +++ b/stats.html @@ -0,0 +1,4044 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 7e8e63f..0000000 --- a/test/test.js +++ /dev/null @@ -1,514 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 array = require( '@stdlib/ndarray-array' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var maybeBroadcastArray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof maybeBroadcastArray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a desired shape which has fewer dimensions than the input array', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 ] - }); - - values = [ - [], - [ 2 ], - [ 2, 2 ], - [ 2, 2, 2 ], - [ 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2, 2, 2 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided a shape with '+values[ i ].length+' dimension' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape having a dimension whose size is less than the corresponding dimension in the input array', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 10, 1 ], - [ 10, 10, 2 ], - [ 10, 10, 9 ], - [ 10, 1, 10 ], - [ 10, 2, 10 ], - [ 10, 9, 10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape and an input array shape which are broadcast-incompatible', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 20, 10 ], - [ 10, 10, 100 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function returns a "base" ndarray instance', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = maybeBroadcastArray( x, [ 2, 2, 2 ] ); - - t.notEqual( y, x, 'returns new instance' ); - t.strictEqual( y instanceof ndarray, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view over the input array data buffer', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = maybeBroadcastArray( x, [ 2, 2, 2 ] ); - - t.strictEqual( y.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; strides)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, -1 ], 3, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; strides)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, 1 ], 2, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; non-contiguous)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ 4, 2 ], 1, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 5 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 7 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (column-major)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'column-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (same shape)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2, 2 ], - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - // Should return the same instance: - t.strictEqual( y, x, 'returns expected value' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 1, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 1, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (same number of dimensions)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1, 2 ], - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (singleton dimension)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (singleton dimension)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 1, 2 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (0-dimensional array)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1 ]; - x = ndarray( 'generic', data, [], [ 0 ], 0, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); From 5d73b06a086aefa6669a58570105cd8c8c09cc48 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 4 Nov 2022 00:31:58 +0000 Subject: [PATCH 023/119] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index f2a827c..6083467 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ }, "dependencies": { "@stdlib/ndarray-base-broadcast-array": "^0.0.x", - "@stdlib/types": "^0.0.x" + "@stdlib/types": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x" }, "devDependencies": { "@stdlib/array-float64": "^0.0.x", @@ -89,4 +90,4 @@ "type": "patreon", "url": "https://www.patreon.com/athan" } -} +} \ No newline at end of file From e90c9925fdb2bf1cd382a4d6b30b8bba7bc078cb Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 4 Nov 2022 08:32:18 +0000 Subject: [PATCH 024/119] Remove files --- index.d.ts | 81 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4044 ------------------------------------------------- 4 files changed, 4130 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index c60cbe5..0000000 --- a/index.d.ts +++ /dev/null @@ -1,81 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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'; -import { ndarray } from '@stdlib/types/ndarray'; - -/** -* Broadcasts an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* ## Notes -* -* - The function throws an error if a provided ndarray is incompatible with a provided shape. -* - If a provided ndarray has the same shape as the specified shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the specified shape, the function returns a new (base) ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to the view may affect multiple elements. If you need to write to the returned array, copy the array before performing operations which may mutate elements. -* - A returned array view is a "base" ndarray, and, thus, a returned array view does not perform bounds checking or afford any of the guarantees of the non-base ndarray constructor. The primary intent of this function is to broadcast an ndarray-like object within internal implementations and to do so with minimal overhead. -* -* @param arr - input array -* @param shape - desired shape -* @throws input array cannot have more dimensions than the desired shape -* @throws input array dimension sizes must be `1` or equal to the corresponding dimension in the provided shape -* @throws input array and desired shape must be broadcast compatible -* @returns broadcasted array -* -* @example -* var array = require( `@stdlib/ndarray/array` ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -*/ -declare function maybeBroadcastArray( arr: ndarray, shape: ArrayLike ): ndarray; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = maybeBroadcastArray; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index eeac6bf..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@esm/index.mjs";function t(t,e){var a,n,s;if(n=e.length,(a=t.shape).length===n){for(s=0;s\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import array from '@stdlib/ndarray-array' ;\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = arr.shape;\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArray;\n"],"names":["maybeBroadcastArray","arr","shape","sh","N","i","length","broadcast"],"mappings":";;gGAoFA,SAASA,EAAqBC,EAAKC,GAClC,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAMI,QACVH,EAAKF,EAAIC,OAGDI,SAAWF,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,KAAQH,EAAOG,GAEvB,OAAOE,EAAWN,EAAKC,GAGzB,OAAOD,CACP,CAED,OAAOM,EAAWN,EAAKC,EACxB"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 1c4063b..0000000 --- a/stats.html +++ /dev/null @@ -1,4044 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From b4980eaedf239859a504c5bde867cf72179aae31 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 4 Nov 2022 08:33:10 +0000 Subject: [PATCH 025/119] 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 | 47 +- benchmark/benchmark.js | 290 -- benchmark/benchmark.ndims.js | 110 - branches.md | 53 - docs/repl.txt | 74 - docs/types/test.ts | 94 - examples/index.js | 45 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 68 - lib/main.js | 111 - package.json | 63 +- stats.html | 4044 +++++++++++++++++++++ test/test.js | 514 --- 38 files changed, 4073 insertions(+), 4372 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/benchmark.ndims.js delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (97%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/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 cc5e6a8..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-11-03T22:41:25.508Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 740d5ce..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/maybe-broadcast-array) 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 3740889..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/maybe-broadcast-array) 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 f89b1b9..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: '45 9 * * 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 + + ```
@@ -160,7 +153,7 @@ for ( i = 0; i < N; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -220,11 +213,11 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-maybe-broadcast-array/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor +[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor/tree/esm -[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes +[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 9763740..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,290 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var ndarrayBase = require( '@stdlib/ndarray-base-ctor' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArray = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::base_ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::base_ndarray,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( out.shape[ 0 ] !== shape[ 0 ] ) { - b.fail( 'unexpected result' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.ndims.js b/benchmark/benchmark.ndims.js deleted file mode 100644 index 1fa371b..0000000 --- a/benchmark/benchmark.ndims.js +++ /dev/null @@ -1,110 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var array = require( '@stdlib/ndarray-array' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} ndims - number of dimensions to which to broadcast -* @returns {Function} benchmark function -*/ -function createBenchmark( ndims ) { - var shape; - var sh; - var x; - var i; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - sh = x.shape; - - shape = []; - for ( i = 0; i < ndims; i++ ) { - shape.push( 0 ); - } - for ( i = ndims; i >= 1; i-- ) { - if ( i > shape.length ) { - shape[ ndims-i ] = 5; - } else { - shape[ ndims-i ] = sh[ i-1 ]; - } - } - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( x, shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var min; - var max; - var f; - var i; - - min = 2; - max = 10; - - for ( i = min; i <= max; i++ ) { - f = createBenchmark( i ); - bench( pkg+'::ndarray,2d:from_ndims=2,to_ndims='+i, f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index b75f357..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/maybe-broadcast-array" -click B href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/main" -click C href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/production" -click D href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/maybe-broadcast-array -[production-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 93528fb..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,74 +0,0 @@ - -{{alias}}( arr, shape ) - Broadcasts an ndarray to a specified shape if and only if the specified - shape differs from the provided ndarray's shape. - - If a provided ndarray has the same shape as the specified shape, the - function returns the provided ndarray. - - If a provided ndarray has a different (broadcast compatible) shape than the - specified shape, the function returns a new (base) ndarray view of the - provided ndarray's data. The view is typically **not** contiguous. As more - than one element of a returned view may refer to the same memory location, - writing to the view may affect multiple elements. If you need to write to - the returned array, copy the array before performing operations which may - mutate elements. - - A returned array is a view on the input array data buffer. The view is - typically *not* contiguous. As more than one element of a returned view may - refer to the same memory location, writing to the view may affect multiple - elements. If you need to write to the returned array, copy the array before - performing operations which may mutate elements. - - A returned array view is a "base" ndarray, and, thus, a returned array view - does not perform bounds checking or afford any of the guarantees of the non- - base ndarray constructor. The primary intent of this function is to - broadcast an ndarray-like object within internal implementations and to do - so with minimal overhead. - - The function throws an error if a provided ndarray is incompatible with a - provided shape. - - Parameters - ---------- - arr: ndarray - Input array. - - shape: ArrayLikeObject - Desired shape. - - Returns - ------- - out: ndarray - Broadcasted array. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > var sh = x.shape - [ 2, 2 ] - > var y = {{alias}}( x, [ 3, 2, 2 ] ) - - > sh = y.shape - [ 3, 2, 2 ] - > var v = y.get( 0, 0, 0 ) - 1 - > v = y.get( 0, 0, 1 ) - 2 - > v = y.get( 0, 1, 0 ) - 3 - > v = y.get( 0, 1, 1 ) - 4 - > v = y.get( 1, 0, 0 ) - 1 - > v = y.get( 1, 1, 0 ) - 3 - > v = y.get( 2, 0, 0 ) - 1 - > v = y.get( 2, 1, 1 ) - 4 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index d7a1a62..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,94 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ndarray } from '@stdlib/types/ndarray'; -import maybeBroadcastArray = require( './index' ); - -/** -* Mock function to create an ndarray-like object. -* -* @return ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns an ndarray... -{ - const x = array(); - - maybeBroadcastArray( x, [ 2, 2, 2 ] ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is not provided a first argument which is an ndarray... -{ - maybeBroadcastArray( '5', [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( 5, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( true, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( false, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( null, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( {}, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( [ '5' ], [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( ( x: number ): number => x, [ 2, 2, 2 ] ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a second argument which is an array-like object containing numbers... -{ - const x = array(); - - maybeBroadcastArray( x, '5' ); // $ExpectError - maybeBroadcastArray( x, 5 ); // $ExpectError - maybeBroadcastArray( x, true ); // $ExpectError - maybeBroadcastArray( x, false ); // $ExpectError - maybeBroadcastArray( x, null ); // $ExpectError - maybeBroadcastArray( x, {} ); // $ExpectError - maybeBroadcastArray( x, [ '5' ] ); // $ExpectError - maybeBroadcastArray( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - - maybeBroadcastArray(); // $ExpectError - maybeBroadcastArray( x ); // $ExpectError - maybeBroadcastArray( x, [ 1, 2, 3 ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index e787d6e..0000000 --- a/examples/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 array = require( '@stdlib/ndarray-array' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var maybeBroadcastArray = require( './../lib' ); - -// Create a 2x2 array: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -// returns - -// Broadcast the array to 3x2x2: -var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -// returns - -// Retrieve the shape: -var sh = y.shape; -// returns [ 3, 2, 2 ] - -// Retrieve the number of elements: -var N = numel( sh ); - -// Loop through the array elements... -var i; -for ( i = 0; i < N; i++ ) { - console.log( 'Y[%s] = %d', ind2sub( sh, i ).join( ', ' ), y.iget( i ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 97% rename from docs/types/index.d.ts rename to index.d.ts index 6c11bdd..c60cbe5 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..eeac6bf --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@esm/index.mjs";function t(t,e){var a,n,s;if(n=e.length,(a=t.shape).length===n){for(s=0;s\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import array from '@stdlib/ndarray-array' ;\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = arr.shape;\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArray;\n"],"names":["maybeBroadcastArray","arr","shape","sh","N","i","length","broadcast"],"mappings":";;gGAoFA,SAASA,EAAqBC,EAAKC,GAClC,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAMI,QACVH,EAAKF,EAAIC,OAGDI,SAAWF,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,KAAQH,EAAOG,GAEvB,OAAOE,EAAWN,EAAKC,GAGzB,OAAOD,CACP,CAED,OAAOM,EAAWN,EAAKC,EACxB"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 834e930..0000000 --- a/lib/index.js +++ /dev/null @@ -1,68 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* @module @stdlib/ndarray-base-maybe-broadcast-array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var maybeBroadcastArray = require( '@stdlib/ndarray-base-maybe-broadcast-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -*/ - -// 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 278f868..0000000 --- a/lib/main.js +++ /dev/null @@ -1,111 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var broadcast = require( '@stdlib/ndarray-base-broadcast-array' ); - - -// MAIN // - -/** -* Broadcasts an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* ## Notes -* -* - If a provided ndarray has the same shape as the specified shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the specified shape, the function returns a new (base) ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to the view may affect multiple elements. If you need to write to the returned array, copy the array before performing operations which may mutate elements. -* -* @param {ndarray} arr - input array -* @param {NonNegativeIntegerArray} shape - desired shape -* @throws {Error} input array cannot have more dimensions than the desired shape -* @throws {Error} input array dimension sizes must be `1` or equal to the corresponding dimension in the provided shape -* @throws {Error} input array and desired shape must be broadcast compatible -* @returns {ndarray} broadcasted array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var y = maybeBroadcastArray( x, [ 3, 2 ] ); -* // throws -*/ -function maybeBroadcastArray( arr, shape ) { - var sh; - var N; - var i; - - N = shape.length; - sh = arr.shape; - - // Check whether we need to broadcast the input array... - if ( sh.length === N ) { - for ( i = 0; i < N; i++ ) { - // Check whether dimensions match... - if ( sh[ i ] !== shape[ i ] ) { - // We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape... - return broadcast( arr, shape ); - } - } - return arr; - } - // If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape... - return broadcast( arr, shape ); -} - - -// EXPORTS // - -module.exports = maybeBroadcastArray; diff --git a/package.json b/package.json index 6083467..97dd5d7 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.1", "description": "Broadcast an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's 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", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,39 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-base-broadcast-array": "^0.0.x", - "@stdlib/types": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.0.x", - "@stdlib/assert-is-ndarray-like": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/ndarray-array": "^0.0.x", - "@stdlib/ndarray-base-ctor": "^0.0.x", - "@stdlib/ndarray-base-numel": "^0.0.x", - "@stdlib/ndarray-ctor": "^0.0.x", - "@stdlib/ndarray-ind2sub": "^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", @@ -85,9 +29,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..1875381 --- /dev/null +++ b/stats.html @@ -0,0 +1,4044 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 7e8e63f..0000000 --- a/test/test.js +++ /dev/null @@ -1,514 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 array = require( '@stdlib/ndarray-array' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var maybeBroadcastArray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof maybeBroadcastArray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a desired shape which has fewer dimensions than the input array', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 ] - }); - - values = [ - [], - [ 2 ], - [ 2, 2 ], - [ 2, 2, 2 ], - [ 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2, 2, 2 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided a shape with '+values[ i ].length+' dimension' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape having a dimension whose size is less than the corresponding dimension in the input array', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 10, 1 ], - [ 10, 10, 2 ], - [ 10, 10, 9 ], - [ 10, 1, 10 ], - [ 10, 2, 10 ], - [ 10, 9, 10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape and an input array shape which are broadcast-incompatible', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 20, 10 ], - [ 10, 10, 100 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function returns a "base" ndarray instance', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = maybeBroadcastArray( x, [ 2, 2, 2 ] ); - - t.notEqual( y, x, 'returns new instance' ); - t.strictEqual( y instanceof ndarray, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view over the input array data buffer', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = maybeBroadcastArray( x, [ 2, 2, 2 ] ); - - t.strictEqual( y.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; strides)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, -1 ], 3, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; strides)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, 1 ], 2, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; non-contiguous)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ 4, 2 ], 1, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 5 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 7 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (column-major)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'column-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (same shape)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2, 2 ], - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - // Should return the same instance: - t.strictEqual( y, x, 'returns expected value' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 1, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 1, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (same number of dimensions)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1, 2 ], - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (singleton dimension)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (singleton dimension)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 1, 2 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (0-dimensional array)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1 ]; - x = ndarray( 'generic', data, [], [ 0 ], 0, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); From 27d64cdcfbea305fda602e1bfe1e46590d6c202c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Dec 2022 04:28:59 +0000 Subject: [PATCH 026/119] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 5893575..19b51b0 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ }, "dependencies": { "@stdlib/ndarray-base-broadcast-array": "^0.0.x", - "@stdlib/types": "^0.0.x" + "@stdlib/types": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x" }, "devDependencies": { "@stdlib/array-float64": "^0.0.x", @@ -89,4 +90,4 @@ "type": "patreon", "url": "https://www.patreon.com/athan" } -} +} \ No newline at end of file From 818cb2f5c2cb36fd2b60828941f2999d5b48f58a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Dec 2022 18:24:56 +0000 Subject: [PATCH 027/119] Remove files --- index.d.ts | 81 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4044 ------------------------------------------------- 4 files changed, 4130 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index c60cbe5..0000000 --- a/index.d.ts +++ /dev/null @@ -1,81 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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'; -import { ndarray } from '@stdlib/types/ndarray'; - -/** -* Broadcasts an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* ## Notes -* -* - The function throws an error if a provided ndarray is incompatible with a provided shape. -* - If a provided ndarray has the same shape as the specified shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the specified shape, the function returns a new (base) ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to the view may affect multiple elements. If you need to write to the returned array, copy the array before performing operations which may mutate elements. -* - A returned array view is a "base" ndarray, and, thus, a returned array view does not perform bounds checking or afford any of the guarantees of the non-base ndarray constructor. The primary intent of this function is to broadcast an ndarray-like object within internal implementations and to do so with minimal overhead. -* -* @param arr - input array -* @param shape - desired shape -* @throws input array cannot have more dimensions than the desired shape -* @throws input array dimension sizes must be `1` or equal to the corresponding dimension in the provided shape -* @throws input array and desired shape must be broadcast compatible -* @returns broadcasted array -* -* @example -* var array = require( `@stdlib/ndarray/array` ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -*/ -declare function maybeBroadcastArray( arr: ndarray, shape: ArrayLike ): ndarray; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = maybeBroadcastArray; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index eeac6bf..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@esm/index.mjs";function t(t,e){var a,n,s;if(n=e.length,(a=t.shape).length===n){for(s=0;s\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import array from '@stdlib/ndarray-array' ;\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = arr.shape;\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArray;\n"],"names":["maybeBroadcastArray","arr","shape","sh","N","i","length","broadcast"],"mappings":";;gGAoFA,SAASA,EAAqBC,EAAKC,GAClC,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAMI,QACVH,EAAKF,EAAIC,OAGDI,SAAWF,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,KAAQH,EAAOG,GAEvB,OAAOE,EAAWN,EAAKC,GAGzB,OAAOD,CACP,CAED,OAAOM,EAAWN,EAAKC,EACxB"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 1875381..0000000 --- a/stats.html +++ /dev/null @@ -1,4044 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 436ba4382ef0bb843cd0c718a54203d5992c0a5f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Dec 2022 18:25:50 +0000 Subject: [PATCH 028/119] 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 | 47 +- benchmark/benchmark.js | 290 -- benchmark/benchmark.ndims.js | 110 - branches.md | 53 - docs/repl.txt | 74 - docs/types/test.ts | 94 - examples/index.js | 45 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 68 - lib/main.js | 111 - package.json | 63 +- stats.html | 4044 +++++++++++++++++++++ test/test.js | 514 --- 38 files changed, 4073 insertions(+), 4377 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/benchmark.ndims.js delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (97%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/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 46ab637..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-12-01T02:30:41.821Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 740d5ce..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/maybe-broadcast-array) 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 3740889..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/maybe-broadcast-array) 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 f89b1b9..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: '45 9 * * 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 + + ```
@@ -160,7 +153,7 @@ for ( i = 0; i < N; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -220,11 +213,11 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-maybe-broadcast-array/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor +[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor/tree/esm -[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes +[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 9763740..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,290 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var ndarrayBase = require( '@stdlib/ndarray-base-ctor' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArray = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::base_ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::base_ndarray,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( out.shape[ 0 ] !== shape[ 0 ] ) { - b.fail( 'unexpected result' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.ndims.js b/benchmark/benchmark.ndims.js deleted file mode 100644 index 1fa371b..0000000 --- a/benchmark/benchmark.ndims.js +++ /dev/null @@ -1,110 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var array = require( '@stdlib/ndarray-array' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} ndims - number of dimensions to which to broadcast -* @returns {Function} benchmark function -*/ -function createBenchmark( ndims ) { - var shape; - var sh; - var x; - var i; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - sh = x.shape; - - shape = []; - for ( i = 0; i < ndims; i++ ) { - shape.push( 0 ); - } - for ( i = ndims; i >= 1; i-- ) { - if ( i > shape.length ) { - shape[ ndims-i ] = 5; - } else { - shape[ ndims-i ] = sh[ i-1 ]; - } - } - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( x, shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var min; - var max; - var f; - var i; - - min = 2; - max = 10; - - for ( i = min; i <= max; i++ ) { - f = createBenchmark( i ); - bench( pkg+'::ndarray,2d:from_ndims=2,to_ndims='+i, f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index b75f357..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/maybe-broadcast-array" -click B href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/main" -click C href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/production" -click D href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/maybe-broadcast-array -[production-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 93528fb..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,74 +0,0 @@ - -{{alias}}( arr, shape ) - Broadcasts an ndarray to a specified shape if and only if the specified - shape differs from the provided ndarray's shape. - - If a provided ndarray has the same shape as the specified shape, the - function returns the provided ndarray. - - If a provided ndarray has a different (broadcast compatible) shape than the - specified shape, the function returns a new (base) ndarray view of the - provided ndarray's data. The view is typically **not** contiguous. As more - than one element of a returned view may refer to the same memory location, - writing to the view may affect multiple elements. If you need to write to - the returned array, copy the array before performing operations which may - mutate elements. - - A returned array is a view on the input array data buffer. The view is - typically *not* contiguous. As more than one element of a returned view may - refer to the same memory location, writing to the view may affect multiple - elements. If you need to write to the returned array, copy the array before - performing operations which may mutate elements. - - A returned array view is a "base" ndarray, and, thus, a returned array view - does not perform bounds checking or afford any of the guarantees of the non- - base ndarray constructor. The primary intent of this function is to - broadcast an ndarray-like object within internal implementations and to do - so with minimal overhead. - - The function throws an error if a provided ndarray is incompatible with a - provided shape. - - Parameters - ---------- - arr: ndarray - Input array. - - shape: ArrayLikeObject - Desired shape. - - Returns - ------- - out: ndarray - Broadcasted array. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > var sh = x.shape - [ 2, 2 ] - > var y = {{alias}}( x, [ 3, 2, 2 ] ) - - > sh = y.shape - [ 3, 2, 2 ] - > var v = y.get( 0, 0, 0 ) - 1 - > v = y.get( 0, 0, 1 ) - 2 - > v = y.get( 0, 1, 0 ) - 3 - > v = y.get( 0, 1, 1 ) - 4 - > v = y.get( 1, 0, 0 ) - 1 - > v = y.get( 1, 1, 0 ) - 3 - > v = y.get( 2, 0, 0 ) - 1 - > v = y.get( 2, 1, 1 ) - 4 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index d7a1a62..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,94 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ndarray } from '@stdlib/types/ndarray'; -import maybeBroadcastArray = require( './index' ); - -/** -* Mock function to create an ndarray-like object. -* -* @return ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns an ndarray... -{ - const x = array(); - - maybeBroadcastArray( x, [ 2, 2, 2 ] ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is not provided a first argument which is an ndarray... -{ - maybeBroadcastArray( '5', [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( 5, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( true, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( false, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( null, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( {}, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( [ '5' ], [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( ( x: number ): number => x, [ 2, 2, 2 ] ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a second argument which is an array-like object containing numbers... -{ - const x = array(); - - maybeBroadcastArray( x, '5' ); // $ExpectError - maybeBroadcastArray( x, 5 ); // $ExpectError - maybeBroadcastArray( x, true ); // $ExpectError - maybeBroadcastArray( x, false ); // $ExpectError - maybeBroadcastArray( x, null ); // $ExpectError - maybeBroadcastArray( x, {} ); // $ExpectError - maybeBroadcastArray( x, [ '5' ] ); // $ExpectError - maybeBroadcastArray( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - - maybeBroadcastArray(); // $ExpectError - maybeBroadcastArray( x ); // $ExpectError - maybeBroadcastArray( x, [ 1, 2, 3 ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index e787d6e..0000000 --- a/examples/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 array = require( '@stdlib/ndarray-array' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var maybeBroadcastArray = require( './../lib' ); - -// Create a 2x2 array: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -// returns - -// Broadcast the array to 3x2x2: -var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -// returns - -// Retrieve the shape: -var sh = y.shape; -// returns [ 3, 2, 2 ] - -// Retrieve the number of elements: -var N = numel( sh ); - -// Loop through the array elements... -var i; -for ( i = 0; i < N; i++ ) { - console.log( 'Y[%s] = %d', ind2sub( sh, i ).join( ', ' ), y.iget( i ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 97% rename from docs/types/index.d.ts rename to index.d.ts index 6c11bdd..c60cbe5 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..eeac6bf --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@esm/index.mjs";function t(t,e){var a,n,s;if(n=e.length,(a=t.shape).length===n){for(s=0;s\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = arr.shape;\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArray;\n"],"names":["maybeBroadcastArray","arr","shape","sh","N","i","length","broadcast"],"mappings":";;gGAoFA,SAASA,EAAqBC,EAAKC,GAClC,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAMI,QACVH,EAAKF,EAAIC,OAGDI,SAAWF,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,KAAQH,EAAOG,GAEvB,OAAOE,EAAWN,EAAKC,GAGzB,OAAOD,CACP,CAED,OAAOM,EAAWN,EAAKC,EACxB"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 834e930..0000000 --- a/lib/index.js +++ /dev/null @@ -1,68 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* @module @stdlib/ndarray-base-maybe-broadcast-array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var maybeBroadcastArray = require( '@stdlib/ndarray-base-maybe-broadcast-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -*/ - -// 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 278f868..0000000 --- a/lib/main.js +++ /dev/null @@ -1,111 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var broadcast = require( '@stdlib/ndarray-base-broadcast-array' ); - - -// MAIN // - -/** -* Broadcasts an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* ## Notes -* -* - If a provided ndarray has the same shape as the specified shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the specified shape, the function returns a new (base) ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to the view may affect multiple elements. If you need to write to the returned array, copy the array before performing operations which may mutate elements. -* -* @param {ndarray} arr - input array -* @param {NonNegativeIntegerArray} shape - desired shape -* @throws {Error} input array cannot have more dimensions than the desired shape -* @throws {Error} input array dimension sizes must be `1` or equal to the corresponding dimension in the provided shape -* @throws {Error} input array and desired shape must be broadcast compatible -* @returns {ndarray} broadcasted array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var y = maybeBroadcastArray( x, [ 3, 2 ] ); -* // throws -*/ -function maybeBroadcastArray( arr, shape ) { - var sh; - var N; - var i; - - N = shape.length; - sh = arr.shape; - - // Check whether we need to broadcast the input array... - if ( sh.length === N ) { - for ( i = 0; i < N; i++ ) { - // Check whether dimensions match... - if ( sh[ i ] !== shape[ i ] ) { - // We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape... - return broadcast( arr, shape ); - } - } - return arr; - } - // If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape... - return broadcast( arr, shape ); -} - - -// EXPORTS // - -module.exports = maybeBroadcastArray; diff --git a/package.json b/package.json index 19b51b0..97dd5d7 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.1", "description": "Broadcast an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's 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", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,39 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-base-broadcast-array": "^0.0.x", - "@stdlib/types": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.0.x", - "@stdlib/assert-is-ndarray-like": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/ndarray-array": "^0.0.x", - "@stdlib/ndarray-base-ctor": "^0.0.x", - "@stdlib/ndarray-base-numel": "^0.0.x", - "@stdlib/ndarray-ctor": "^0.0.x", - "@stdlib/ndarray-ind2sub": "^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", @@ -85,9 +29,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..f6c997a --- /dev/null +++ b/stats.html @@ -0,0 +1,4044 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 7e8e63f..0000000 --- a/test/test.js +++ /dev/null @@ -1,514 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 array = require( '@stdlib/ndarray-array' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var maybeBroadcastArray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof maybeBroadcastArray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a desired shape which has fewer dimensions than the input array', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 ] - }); - - values = [ - [], - [ 2 ], - [ 2, 2 ], - [ 2, 2, 2 ], - [ 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2, 2, 2 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided a shape with '+values[ i ].length+' dimension' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape having a dimension whose size is less than the corresponding dimension in the input array', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 10, 1 ], - [ 10, 10, 2 ], - [ 10, 10, 9 ], - [ 10, 1, 10 ], - [ 10, 2, 10 ], - [ 10, 9, 10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape and an input array shape which are broadcast-incompatible', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 20, 10 ], - [ 10, 10, 100 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function returns a "base" ndarray instance', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = maybeBroadcastArray( x, [ 2, 2, 2 ] ); - - t.notEqual( y, x, 'returns new instance' ); - t.strictEqual( y instanceof ndarray, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view over the input array data buffer', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = maybeBroadcastArray( x, [ 2, 2, 2 ] ); - - t.strictEqual( y.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; strides)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, -1 ], 3, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; strides)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, 1 ], 2, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; non-contiguous)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ 4, 2 ], 1, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 5 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 7 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (column-major)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'column-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (same shape)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2, 2 ], - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - // Should return the same instance: - t.strictEqual( y, x, 'returns expected value' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 1, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 1, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (same number of dimensions)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1, 2 ], - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (singleton dimension)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (singleton dimension)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 1, 2 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (0-dimensional array)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1 ]; - x = ndarray( 'generic', data, [], [ 0 ], 0, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); From 9ab15d5adc6ef1ca91a34779a78ea984f9e400a4 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Feb 2023 04:14:02 +0000 Subject: [PATCH 029/119] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 8af92f2..8e066d0 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ }, "dependencies": { "@stdlib/ndarray-base-broadcast-array": "^0.0.x", - "@stdlib/types": "^0.0.x" + "@stdlib/types": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x" }, "devDependencies": { "@stdlib/array-float64": "^0.0.x", @@ -89,4 +90,4 @@ "type": "patreon", "url": "https://www.patreon.com/athan" } -} +} \ No newline at end of file From 74404d7aa7bb062e49d8a6b481b89c4b01f5aaaf Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Feb 2023 13:01:58 +0000 Subject: [PATCH 030/119] Remove files --- index.d.ts | 81 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4044 ------------------------------------------------- 4 files changed, 4130 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index c60cbe5..0000000 --- a/index.d.ts +++ /dev/null @@ -1,81 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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'; -import { ndarray } from '@stdlib/types/ndarray'; - -/** -* Broadcasts an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* ## Notes -* -* - The function throws an error if a provided ndarray is incompatible with a provided shape. -* - If a provided ndarray has the same shape as the specified shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the specified shape, the function returns a new (base) ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to the view may affect multiple elements. If you need to write to the returned array, copy the array before performing operations which may mutate elements. -* - A returned array view is a "base" ndarray, and, thus, a returned array view does not perform bounds checking or afford any of the guarantees of the non-base ndarray constructor. The primary intent of this function is to broadcast an ndarray-like object within internal implementations and to do so with minimal overhead. -* -* @param arr - input array -* @param shape - desired shape -* @throws input array cannot have more dimensions than the desired shape -* @throws input array dimension sizes must be `1` or equal to the corresponding dimension in the provided shape -* @throws input array and desired shape must be broadcast compatible -* @returns broadcasted array -* -* @example -* var array = require( `@stdlib/ndarray/array` ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -*/ -declare function maybeBroadcastArray( arr: ndarray, shape: ArrayLike ): ndarray; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = maybeBroadcastArray; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index eeac6bf..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@esm/index.mjs";function t(t,e){var a,n,s;if(n=e.length,(a=t.shape).length===n){for(s=0;s\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = arr.shape;\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArray;\n"],"names":["maybeBroadcastArray","arr","shape","sh","N","i","length","broadcast"],"mappings":";;gGAoFA,SAASA,EAAqBC,EAAKC,GAClC,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAMI,QACVH,EAAKF,EAAIC,OAGDI,SAAWF,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,KAAQH,EAAOG,GAEvB,OAAOE,EAAWN,EAAKC,GAGzB,OAAOD,CACP,CAED,OAAOM,EAAWN,EAAKC,EACxB"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index f6c997a..0000000 --- a/stats.html +++ /dev/null @@ -1,4044 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 2a9ca0a9fa2953f68cb9e3b0937419fa9f7481f6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Feb 2023 13:03:11 +0000 Subject: [PATCH 031/119] 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 | 47 +- benchmark/benchmark.js | 290 - benchmark/benchmark.ndims.js | 110 - branches.md | 53 - docs/repl.txt | 74 - docs/types/test.ts | 94 - examples/index.js | 45 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 68 - lib/main.js | 111 - package.json | 63 +- stats.html | 6177 +++++++++++++++++++++ test/test.js | 514 -- 38 files changed, 6206 insertions(+), 4388 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/benchmark.ndims.js delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (97%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/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 f757e84..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-02-01T02:28:09.076Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 740d5ce..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/maybe-broadcast-array) 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 3740889..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/maybe-broadcast-array) 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 f89b1b9..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: '45 9 * * 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 + + ```
@@ -160,7 +153,7 @@ for ( i = 0; i < N; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -220,11 +213,11 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-maybe-broadcast-array/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor +[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor/tree/esm -[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes +[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 9763740..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,290 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var ndarrayBase = require( '@stdlib/ndarray-base-ctor' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArray = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::base_ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::base_ndarray,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( out.shape[ 0 ] !== shape[ 0 ] ) { - b.fail( 'unexpected result' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.ndims.js b/benchmark/benchmark.ndims.js deleted file mode 100644 index 1fa371b..0000000 --- a/benchmark/benchmark.ndims.js +++ /dev/null @@ -1,110 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var array = require( '@stdlib/ndarray-array' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} ndims - number of dimensions to which to broadcast -* @returns {Function} benchmark function -*/ -function createBenchmark( ndims ) { - var shape; - var sh; - var x; - var i; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - sh = x.shape; - - shape = []; - for ( i = 0; i < ndims; i++ ) { - shape.push( 0 ); - } - for ( i = ndims; i >= 1; i-- ) { - if ( i > shape.length ) { - shape[ ndims-i ] = 5; - } else { - shape[ ndims-i ] = sh[ i-1 ]; - } - } - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( x, shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var min; - var max; - var f; - var i; - - min = 2; - max = 10; - - for ( i = min; i <= max; i++ ) { - f = createBenchmark( i ); - bench( pkg+'::ndarray,2d:from_ndims=2,to_ndims='+i, f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index b75f357..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/maybe-broadcast-array" -click B href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/main" -click C href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/production" -click D href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/maybe-broadcast-array -[production-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 93528fb..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,74 +0,0 @@ - -{{alias}}( arr, shape ) - Broadcasts an ndarray to a specified shape if and only if the specified - shape differs from the provided ndarray's shape. - - If a provided ndarray has the same shape as the specified shape, the - function returns the provided ndarray. - - If a provided ndarray has a different (broadcast compatible) shape than the - specified shape, the function returns a new (base) ndarray view of the - provided ndarray's data. The view is typically **not** contiguous. As more - than one element of a returned view may refer to the same memory location, - writing to the view may affect multiple elements. If you need to write to - the returned array, copy the array before performing operations which may - mutate elements. - - A returned array is a view on the input array data buffer. The view is - typically *not* contiguous. As more than one element of a returned view may - refer to the same memory location, writing to the view may affect multiple - elements. If you need to write to the returned array, copy the array before - performing operations which may mutate elements. - - A returned array view is a "base" ndarray, and, thus, a returned array view - does not perform bounds checking or afford any of the guarantees of the non- - base ndarray constructor. The primary intent of this function is to - broadcast an ndarray-like object within internal implementations and to do - so with minimal overhead. - - The function throws an error if a provided ndarray is incompatible with a - provided shape. - - Parameters - ---------- - arr: ndarray - Input array. - - shape: ArrayLikeObject - Desired shape. - - Returns - ------- - out: ndarray - Broadcasted array. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > var sh = x.shape - [ 2, 2 ] - > var y = {{alias}}( x, [ 3, 2, 2 ] ) - - > sh = y.shape - [ 3, 2, 2 ] - > var v = y.get( 0, 0, 0 ) - 1 - > v = y.get( 0, 0, 1 ) - 2 - > v = y.get( 0, 1, 0 ) - 3 - > v = y.get( 0, 1, 1 ) - 4 - > v = y.get( 1, 0, 0 ) - 1 - > v = y.get( 1, 1, 0 ) - 3 - > v = y.get( 2, 0, 0 ) - 1 - > v = y.get( 2, 1, 1 ) - 4 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index d7a1a62..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,94 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ndarray } from '@stdlib/types/ndarray'; -import maybeBroadcastArray = require( './index' ); - -/** -* Mock function to create an ndarray-like object. -* -* @return ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns an ndarray... -{ - const x = array(); - - maybeBroadcastArray( x, [ 2, 2, 2 ] ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is not provided a first argument which is an ndarray... -{ - maybeBroadcastArray( '5', [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( 5, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( true, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( false, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( null, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( {}, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( [ '5' ], [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( ( x: number ): number => x, [ 2, 2, 2 ] ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a second argument which is an array-like object containing numbers... -{ - const x = array(); - - maybeBroadcastArray( x, '5' ); // $ExpectError - maybeBroadcastArray( x, 5 ); // $ExpectError - maybeBroadcastArray( x, true ); // $ExpectError - maybeBroadcastArray( x, false ); // $ExpectError - maybeBroadcastArray( x, null ); // $ExpectError - maybeBroadcastArray( x, {} ); // $ExpectError - maybeBroadcastArray( x, [ '5' ] ); // $ExpectError - maybeBroadcastArray( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - - maybeBroadcastArray(); // $ExpectError - maybeBroadcastArray( x ); // $ExpectError - maybeBroadcastArray( x, [ 1, 2, 3 ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index e787d6e..0000000 --- a/examples/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 array = require( '@stdlib/ndarray-array' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var maybeBroadcastArray = require( './../lib' ); - -// Create a 2x2 array: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -// returns - -// Broadcast the array to 3x2x2: -var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -// returns - -// Retrieve the shape: -var sh = y.shape; -// returns [ 3, 2, 2 ] - -// Retrieve the number of elements: -var N = numel( sh ); - -// Loop through the array elements... -var i; -for ( i = 0; i < N; i++ ) { - console.log( 'Y[%s] = %d', ind2sub( sh, i ).join( ', ' ), y.iget( i ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 97% rename from docs/types/index.d.ts rename to index.d.ts index 6c11bdd..c60cbe5 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..15c5d13 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@esm/index.mjs";function t(t,e){var a,n,s;if(n=e.length,(a=t.shape).length===n){for(s=0;s\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = arr.shape;\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArray;\n"],"names":["maybeBroadcastArray","arr","shape","sh","N","i","length","broadcast"],"mappings":";;gGAoFA,SAASA,EAAqBC,EAAKC,GAClC,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAMI,QACVH,EAAKF,EAAIC,OAGDI,SAAWF,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,KAAQH,EAAOG,GAEvB,OAAOE,EAAWN,EAAKC,GAGzB,OAAOD,CACP,CAED,OAAOM,EAAWN,EAAKC,EACxB"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 834e930..0000000 --- a/lib/index.js +++ /dev/null @@ -1,68 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* @module @stdlib/ndarray-base-maybe-broadcast-array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var maybeBroadcastArray = require( '@stdlib/ndarray-base-maybe-broadcast-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -*/ - -// 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 278f868..0000000 --- a/lib/main.js +++ /dev/null @@ -1,111 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var broadcast = require( '@stdlib/ndarray-base-broadcast-array' ); - - -// MAIN // - -/** -* Broadcasts an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* ## Notes -* -* - If a provided ndarray has the same shape as the specified shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the specified shape, the function returns a new (base) ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to the view may affect multiple elements. If you need to write to the returned array, copy the array before performing operations which may mutate elements. -* -* @param {ndarray} arr - input array -* @param {NonNegativeIntegerArray} shape - desired shape -* @throws {Error} input array cannot have more dimensions than the desired shape -* @throws {Error} input array dimension sizes must be `1` or equal to the corresponding dimension in the provided shape -* @throws {Error} input array and desired shape must be broadcast compatible -* @returns {ndarray} broadcasted array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var y = maybeBroadcastArray( x, [ 3, 2 ] ); -* // throws -*/ -function maybeBroadcastArray( arr, shape ) { - var sh; - var N; - var i; - - N = shape.length; - sh = arr.shape; - - // Check whether we need to broadcast the input array... - if ( sh.length === N ) { - for ( i = 0; i < N; i++ ) { - // Check whether dimensions match... - if ( sh[ i ] !== shape[ i ] ) { - // We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape... - return broadcast( arr, shape ); - } - } - return arr; - } - // If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape... - return broadcast( arr, shape ); -} - - -// EXPORTS // - -module.exports = maybeBroadcastArray; diff --git a/package.json b/package.json index 8e066d0..97dd5d7 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.1", "description": "Broadcast an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's 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", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,39 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-base-broadcast-array": "^0.0.x", - "@stdlib/types": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.0.x", - "@stdlib/assert-is-ndarray-like": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/ndarray-array": "^0.0.x", - "@stdlib/ndarray-base-ctor": "^0.0.x", - "@stdlib/ndarray-base-numel": "^0.0.x", - "@stdlib/ndarray-ctor": "^0.0.x", - "@stdlib/ndarray-ind2sub": "^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", @@ -85,9 +29,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..ecd3d1a --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 7e8e63f..0000000 --- a/test/test.js +++ /dev/null @@ -1,514 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 array = require( '@stdlib/ndarray-array' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var maybeBroadcastArray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof maybeBroadcastArray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a desired shape which has fewer dimensions than the input array', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 ] - }); - - values = [ - [], - [ 2 ], - [ 2, 2 ], - [ 2, 2, 2 ], - [ 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2, 2, 2 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided a shape with '+values[ i ].length+' dimension' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape having a dimension whose size is less than the corresponding dimension in the input array', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 10, 1 ], - [ 10, 10, 2 ], - [ 10, 10, 9 ], - [ 10, 1, 10 ], - [ 10, 2, 10 ], - [ 10, 9, 10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape and an input array shape which are broadcast-incompatible', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 20, 10 ], - [ 10, 10, 100 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function returns a "base" ndarray instance', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = maybeBroadcastArray( x, [ 2, 2, 2 ] ); - - t.notEqual( y, x, 'returns new instance' ); - t.strictEqual( y instanceof ndarray, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view over the input array data buffer', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = maybeBroadcastArray( x, [ 2, 2, 2 ] ); - - t.strictEqual( y.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; strides)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, -1 ], 3, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; strides)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, 1 ], 2, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; non-contiguous)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ 4, 2 ], 1, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 5 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 7 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (column-major)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'column-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (same shape)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2, 2 ], - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - // Should return the same instance: - t.strictEqual( y, x, 'returns expected value' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 1, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 1, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (same number of dimensions)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1, 2 ], - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (singleton dimension)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (singleton dimension)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 1, 2 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (0-dimensional array)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1 ]; - x = ndarray( 'generic', data, [], [ 0 ], 0, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); From 061d5c02cee09a629317002e1ac7064653ec16f1 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 24 Sep 2023 15:40:30 +0000 Subject: [PATCH 032/119] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 688d9ed..1ea62a5 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ }, "dependencies": { "@stdlib/ndarray-base-broadcast-array": "^0.1.0", - "@stdlib/types": "^0.1.0" + "@stdlib/types": "^0.1.0", + "@stdlib/error-tools-fmtprodmsg": "^0.1.0" }, "devDependencies": { "@stdlib/array-float64": "^0.1.0", @@ -89,4 +90,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From d89328bfa2aa99e6cd3e3b23e69d0a1215a98d2c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 24 Sep 2023 15:44:27 +0000 Subject: [PATCH 033/119] Remove files --- index.d.ts | 81 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6263 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index c60cbe5..0000000 --- a/index.d.ts +++ /dev/null @@ -1,81 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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'; -import { ndarray } from '@stdlib/types/ndarray'; - -/** -* Broadcasts an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* ## Notes -* -* - The function throws an error if a provided ndarray is incompatible with a provided shape. -* - If a provided ndarray has the same shape as the specified shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the specified shape, the function returns a new (base) ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to the view may affect multiple elements. If you need to write to the returned array, copy the array before performing operations which may mutate elements. -* - A returned array view is a "base" ndarray, and, thus, a returned array view does not perform bounds checking or afford any of the guarantees of the non-base ndarray constructor. The primary intent of this function is to broadcast an ndarray-like object within internal implementations and to do so with minimal overhead. -* -* @param arr - input array -* @param shape - desired shape -* @throws input array cannot have more dimensions than the desired shape -* @throws input array dimension sizes must be `1` or equal to the corresponding dimension in the provided shape -* @throws input array and desired shape must be broadcast compatible -* @returns broadcasted array -* -* @example -* var array = require( `@stdlib/ndarray/array` ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -*/ -declare function maybeBroadcastArray( arr: ndarray, shape: ArrayLike ): ndarray; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = maybeBroadcastArray; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 15c5d13..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@esm/index.mjs";function t(t,e){var a,n,s;if(n=e.length,(a=t.shape).length===n){for(s=0;s\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = arr.shape;\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArray;\n"],"names":["maybeBroadcastArray","arr","shape","sh","N","i","length","broadcast"],"mappings":";;gGAoFA,SAASA,EAAqBC,EAAKC,GAClC,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAMI,QACVH,EAAKF,EAAIC,OAGDI,SAAWF,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,KAAQH,EAAOG,GAEvB,OAAOE,EAAWN,EAAKC,GAGzB,OAAOD,CACP,CAED,OAAOM,EAAWN,EAAKC,EACxB"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index ecd3d1a..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From e1fd18f4c3f799a872ee147a34ea6b0f0a47df0d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 24 Sep 2023 15:45:29 +0000 Subject: [PATCH 034/119] 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 | 47 +- benchmark/benchmark.js | 290 - benchmark/benchmark.ndims.js | 110 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 74 - docs/types/test.ts | 94 - examples/index.js | 45 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 68 - lib/main.js | 111 - package.json | 63 +- stats.html | 6177 +++++++++++++++++++++ test/test.js | 514 -- 41 files changed, 6206 insertions(+), 4563 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/benchmark.ndims.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (97%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/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 740d5ce..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/maybe-broadcast-array) 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 3740889..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/maybe-broadcast-array) 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 f89b1b9..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: '45 9 * * 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 + + ```
@@ -171,7 +164,7 @@ for ( i = 0; i < N; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -231,11 +224,11 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-maybe-broadcast-array/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor +[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor/tree/esm -[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes +[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 9763740..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,290 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var ndarrayBase = require( '@stdlib/ndarray-base-ctor' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArray = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::base_ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::base_ndarray,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( out.shape[ 0 ] !== shape[ 0 ] ) { - b.fail( 'unexpected result' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.ndims.js b/benchmark/benchmark.ndims.js deleted file mode 100644 index 1fa371b..0000000 --- a/benchmark/benchmark.ndims.js +++ /dev/null @@ -1,110 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var array = require( '@stdlib/ndarray-array' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} ndims - number of dimensions to which to broadcast -* @returns {Function} benchmark function -*/ -function createBenchmark( ndims ) { - var shape; - var sh; - var x; - var i; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - sh = x.shape; - - shape = []; - for ( i = 0; i < ndims; i++ ) { - shape.push( 0 ); - } - for ( i = ndims; i >= 1; i-- ) { - if ( i > shape.length ) { - shape[ ndims-i ] = 5; - } else { - shape[ ndims-i ] = sh[ i-1 ]; - } - } - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( x, shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var min; - var max; - var f; - var i; - - min = 2; - max = 10; - - for ( i = min; i <= max; i++ ) { - f = createBenchmark( i ); - bench( pkg+'::ndarray,2d:from_ndims=2,to_ndims='+i, f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index 90d11e3..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/maybe-broadcast-array" -%% click B href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/maybe-broadcast-array -[production-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 71859ce..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import maybeBroadcastArray from '../docs/types/index'; -export = maybeBroadcastArray; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 2ae3059..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var o=function(t,r){return function(){return r||t((r={exports:{}}).exports,r),r.exports}};var s=o(function(b,a){ -var u=require('@stdlib/ndarray-base-broadcast-array/dist');function c(t,r){var i,n,e;if(n=r.length,i=t.shape,i.length===n){for(e=0;e\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = arr.shape;\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nmodule.exports = maybeBroadcastArray;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape.\n*\n* @module @stdlib/ndarray-base-maybe-broadcast-array\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var maybeBroadcastArray = require( '@stdlib/ndarray-base-maybe-broadcast-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAY,QAAS,sCAAuC,EA8DhE,SAASC,EAAqBC,EAAKC,EAAQ,CAC1C,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAM,OACVC,EAAKF,EAAI,MAGJE,EAAG,SAAWC,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,CAAE,IAAMH,EAAOG,CAAE,EAEzB,OAAON,EAAWE,EAAKC,CAAM,EAG/B,OAAOD,CACR,CAEA,OAAOF,EAAWE,EAAKC,CAAM,CAC9B,CAKAJ,EAAO,QAAUE,IChDjB,IAAIM,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "broadcast", "maybeBroadcastArray", "arr", "shape", "sh", "N", "i", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 93528fb..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,74 +0,0 @@ - -{{alias}}( arr, shape ) - Broadcasts an ndarray to a specified shape if and only if the specified - shape differs from the provided ndarray's shape. - - If a provided ndarray has the same shape as the specified shape, the - function returns the provided ndarray. - - If a provided ndarray has a different (broadcast compatible) shape than the - specified shape, the function returns a new (base) ndarray view of the - provided ndarray's data. The view is typically **not** contiguous. As more - than one element of a returned view may refer to the same memory location, - writing to the view may affect multiple elements. If you need to write to - the returned array, copy the array before performing operations which may - mutate elements. - - A returned array is a view on the input array data buffer. The view is - typically *not* contiguous. As more than one element of a returned view may - refer to the same memory location, writing to the view may affect multiple - elements. If you need to write to the returned array, copy the array before - performing operations which may mutate elements. - - A returned array view is a "base" ndarray, and, thus, a returned array view - does not perform bounds checking or afford any of the guarantees of the non- - base ndarray constructor. The primary intent of this function is to - broadcast an ndarray-like object within internal implementations and to do - so with minimal overhead. - - The function throws an error if a provided ndarray is incompatible with a - provided shape. - - Parameters - ---------- - arr: ndarray - Input array. - - shape: ArrayLikeObject - Desired shape. - - Returns - ------- - out: ndarray - Broadcasted array. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > var sh = x.shape - [ 2, 2 ] - > var y = {{alias}}( x, [ 3, 2, 2 ] ) - - > sh = y.shape - [ 3, 2, 2 ] - > var v = y.get( 0, 0, 0 ) - 1 - > v = y.get( 0, 0, 1 ) - 2 - > v = y.get( 0, 1, 0 ) - 3 - > v = y.get( 0, 1, 1 ) - 4 - > v = y.get( 1, 0, 0 ) - 1 - > v = y.get( 1, 1, 0 ) - 3 - > v = y.get( 2, 0, 0 ) - 1 - > v = y.get( 2, 1, 1 ) - 4 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index d7a1a62..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,94 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ndarray } from '@stdlib/types/ndarray'; -import maybeBroadcastArray = require( './index' ); - -/** -* Mock function to create an ndarray-like object. -* -* @return ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns an ndarray... -{ - const x = array(); - - maybeBroadcastArray( x, [ 2, 2, 2 ] ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is not provided a first argument which is an ndarray... -{ - maybeBroadcastArray( '5', [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( 5, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( true, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( false, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( null, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( {}, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( [ '5' ], [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( ( x: number ): number => x, [ 2, 2, 2 ] ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a second argument which is an array-like object containing numbers... -{ - const x = array(); - - maybeBroadcastArray( x, '5' ); // $ExpectError - maybeBroadcastArray( x, 5 ); // $ExpectError - maybeBroadcastArray( x, true ); // $ExpectError - maybeBroadcastArray( x, false ); // $ExpectError - maybeBroadcastArray( x, null ); // $ExpectError - maybeBroadcastArray( x, {} ); // $ExpectError - maybeBroadcastArray( x, [ '5' ] ); // $ExpectError - maybeBroadcastArray( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - - maybeBroadcastArray(); // $ExpectError - maybeBroadcastArray( x ); // $ExpectError - maybeBroadcastArray( x, [ 1, 2, 3 ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index e787d6e..0000000 --- a/examples/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 array = require( '@stdlib/ndarray-array' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var maybeBroadcastArray = require( './../lib' ); - -// Create a 2x2 array: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -// returns - -// Broadcast the array to 3x2x2: -var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -// returns - -// Retrieve the shape: -var sh = y.shape; -// returns [ 3, 2, 2 ] - -// Retrieve the number of elements: -var N = numel( sh ); - -// Loop through the array elements... -var i; -for ( i = 0; i < N; i++ ) { - console.log( 'Y[%s] = %d', ind2sub( sh, i ).join( ', ' ), y.iget( i ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 97% rename from docs/types/index.d.ts rename to index.d.ts index 39826a4..679c9f1 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..15c5d13 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@esm/index.mjs";function t(t,e){var a,n,s;if(n=e.length,(a=t.shape).length===n){for(s=0;s\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = arr.shape;\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArray;\n"],"names":["maybeBroadcastArray","arr","shape","sh","N","i","length","broadcast"],"mappings":";;gGAoFA,SAASA,EAAqBC,EAAKC,GAClC,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAMI,QACVH,EAAKF,EAAIC,OAGDI,SAAWF,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,KAAQH,EAAOG,GAEvB,OAAOE,EAAWN,EAAKC,GAGzB,OAAOD,CACP,CAED,OAAOM,EAAWN,EAAKC,EACxB"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 834e930..0000000 --- a/lib/index.js +++ /dev/null @@ -1,68 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* @module @stdlib/ndarray-base-maybe-broadcast-array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var maybeBroadcastArray = require( '@stdlib/ndarray-base-maybe-broadcast-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -*/ - -// 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 278f868..0000000 --- a/lib/main.js +++ /dev/null @@ -1,111 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var broadcast = require( '@stdlib/ndarray-base-broadcast-array' ); - - -// MAIN // - -/** -* Broadcasts an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* ## Notes -* -* - If a provided ndarray has the same shape as the specified shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the specified shape, the function returns a new (base) ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to the view may affect multiple elements. If you need to write to the returned array, copy the array before performing operations which may mutate elements. -* -* @param {ndarray} arr - input array -* @param {NonNegativeIntegerArray} shape - desired shape -* @throws {Error} input array cannot have more dimensions than the desired shape -* @throws {Error} input array dimension sizes must be `1` or equal to the corresponding dimension in the provided shape -* @throws {Error} input array and desired shape must be broadcast compatible -* @returns {ndarray} broadcasted array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var y = maybeBroadcastArray( x, [ 3, 2 ] ); -* // throws -*/ -function maybeBroadcastArray( arr, shape ) { - var sh; - var N; - var i; - - N = shape.length; - sh = arr.shape; - - // Check whether we need to broadcast the input array... - if ( sh.length === N ) { - for ( i = 0; i < N; i++ ) { - // Check whether dimensions match... - if ( sh[ i ] !== shape[ i ] ) { - // We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape... - return broadcast( arr, shape ); - } - } - return arr; - } - // If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape... - return broadcast( arr, shape ); -} - - -// EXPORTS // - -module.exports = maybeBroadcastArray; diff --git a/package.json b/package.json index 1ea62a5..b74d597 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Broadcast an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's 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", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,39 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-base-broadcast-array": "^0.1.0", - "@stdlib/types": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.0" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.1.0", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/bench": "^0.1.0", - "@stdlib/ndarray-array": "^0.0.9", - "@stdlib/ndarray-base-ctor": "^0.1.0", - "@stdlib/ndarray-base-numel": "^0.1.0", - "@stdlib/ndarray-ctor": "^0.0.10", - "@stdlib/ndarray-ind2sub": "^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", @@ -85,9 +29,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..f6c7aec --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 7e8e63f..0000000 --- a/test/test.js +++ /dev/null @@ -1,514 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 array = require( '@stdlib/ndarray-array' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var maybeBroadcastArray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof maybeBroadcastArray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a desired shape which has fewer dimensions than the input array', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 ] - }); - - values = [ - [], - [ 2 ], - [ 2, 2 ], - [ 2, 2, 2 ], - [ 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2, 2, 2 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided a shape with '+values[ i ].length+' dimension' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape having a dimension whose size is less than the corresponding dimension in the input array', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 10, 1 ], - [ 10, 10, 2 ], - [ 10, 10, 9 ], - [ 10, 1, 10 ], - [ 10, 2, 10 ], - [ 10, 9, 10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape and an input array shape which are broadcast-incompatible', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 20, 10 ], - [ 10, 10, 100 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function returns a "base" ndarray instance', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = maybeBroadcastArray( x, [ 2, 2, 2 ] ); - - t.notEqual( y, x, 'returns new instance' ); - t.strictEqual( y instanceof ndarray, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view over the input array data buffer', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = maybeBroadcastArray( x, [ 2, 2, 2 ] ); - - t.strictEqual( y.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; strides)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, -1 ], 3, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; strides)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, 1 ], 2, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; non-contiguous)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ 4, 2 ], 1, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 5 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 7 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (column-major)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'column-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (same shape)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2, 2 ], - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - // Should return the same instance: - t.strictEqual( y, x, 'returns expected value' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 1, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 1, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (same number of dimensions)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1, 2 ], - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (singleton dimension)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (singleton dimension)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 1, 2 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (0-dimensional array)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1 ]; - x = ndarray( 'generic', data, [], [ 0 ], 0, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); From 9e3536990587e11b46704044da1d61dbbd98e506 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 24 Sep 2023 15:50:46 +0000 Subject: [PATCH 035/119] Update README.md for ESM bundle v0.1.0 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 306215c..a9b1414 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ limitations under the License. ## Usage ```javascript -import maybeBroadcastArray from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-maybe-broadcast-array@esm/index.mjs'; +import maybeBroadcastArray from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-maybe-broadcast-array@v0.1.0-esm/index.mjs'; ``` #### maybeBroadcastArray( arr, shape ) @@ -107,7 +107,7 @@ var y = maybeBroadcastArray( x, [ 2, 2, 2 ] ); import array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-array@esm/index.mjs'; import numel from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@esm/index.mjs'; import ind2sub from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ind2sub@esm/index.mjs'; -import maybeBroadcastArray from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-maybe-broadcast-array@esm/index.mjs'; +import maybeBroadcastArray from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-maybe-broadcast-array@v0.1.0-esm/index.mjs'; // Create a 2x2 array: var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); From d0c63e7c03f664e56dbbbc796a68b7a581029594 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 24 Sep 2023 15:50:47 +0000 Subject: [PATCH 036/119] Auto-generated commit --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a9b1414..2e91369 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,11 @@ limitations under the License. ## Usage +```javascript +import maybeBroadcastArray from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-maybe-broadcast-array@esm/index.mjs'; +``` +The previous example will load the latest bundled code from the esm branch. Alternatively, you may load a specific version by loading the file from one of the [tagged bundles](https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tags). For example, + ```javascript import maybeBroadcastArray from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-maybe-broadcast-array@v0.1.0-esm/index.mjs'; ``` @@ -107,7 +112,7 @@ var y = maybeBroadcastArray( x, [ 2, 2, 2 ] ); import array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-array@esm/index.mjs'; import numel from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@esm/index.mjs'; import ind2sub from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ind2sub@esm/index.mjs'; -import maybeBroadcastArray from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-maybe-broadcast-array@v0.1.0-esm/index.mjs'; +import maybeBroadcastArray from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-maybe-broadcast-array@esm/index.mjs'; // Create a 2x2 array: var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); From f7ff359a7432079102afb42b206d87b7ea9cecbd Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Oct 2023 16:23:43 +0000 Subject: [PATCH 037/119] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 1d50766..b362ea7 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ }, "dependencies": { "@stdlib/ndarray-base-broadcast-array": "^0.1.0", - "@stdlib/types": "^0.1.0" + "@stdlib/types": "^0.1.0", + "@stdlib/error-tools-fmtprodmsg": "^0.1.0" }, "devDependencies": { "@stdlib/array-float64": "^0.1.0", @@ -89,4 +90,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From cc64cd50c4ed4630c7f8f50497ae808270305903 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 3 Oct 2023 01:30:38 +0000 Subject: [PATCH 038/119] Remove files --- index.d.ts | 81 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6263 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 679c9f1..0000000 --- a/index.d.ts +++ /dev/null @@ -1,81 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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'; -import { ndarray } from '@stdlib/types/ndarray'; - -/** -* Broadcasts an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* ## Notes -* -* - The function throws an error if a provided ndarray is incompatible with a provided shape. -* - If a provided ndarray has the same shape as the specified shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the specified shape, the function returns a new (base) ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to the view may affect multiple elements. If you need to write to the returned array, copy the array before performing operations which may mutate elements. -* - A returned array view is a "base" ndarray, and, thus, a returned array view does not perform bounds checking or afford any of the guarantees of the non-base ndarray constructor. The primary intent of this function is to broadcast an ndarray-like object within internal implementations and to do so with minimal overhead. -* -* @param arr - input array -* @param shape - desired shape -* @throws input array cannot have more dimensions than the desired shape -* @throws input array dimension sizes must be `1` or equal to the corresponding dimension in the provided shape -* @throws input array and desired shape must be broadcast compatible -* @returns broadcasted array -* -* @example -* var array = require( `@stdlib/ndarray/array` ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -*/ -declare function maybeBroadcastArray( arr: ndarray, shape: ArrayLike ): ndarray; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = maybeBroadcastArray; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 15c5d13..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@esm/index.mjs";function t(t,e){var a,n,s;if(n=e.length,(a=t.shape).length===n){for(s=0;s\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = arr.shape;\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArray;\n"],"names":["maybeBroadcastArray","arr","shape","sh","N","i","length","broadcast"],"mappings":";;gGAoFA,SAASA,EAAqBC,EAAKC,GAClC,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAMI,QACVH,EAAKF,EAAIC,OAGDI,SAAWF,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,KAAQH,EAAOG,GAEvB,OAAOE,EAAWN,EAAKC,GAGzB,OAAOD,CACP,CAED,OAAOM,EAAWN,EAAKC,EACxB"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index f6c7aec..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 019ea6f6c440e4c307382e25e9c04b66085d51d8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 3 Oct 2023 01:31:25 +0000 Subject: [PATCH 039/119] 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 | 47 +- benchmark/benchmark.js | 290 - benchmark/benchmark.ndims.js | 110 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 74 - docs/types/test.ts | 94 - examples/index.js | 45 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 68 - lib/main.js | 111 - package.json | 63 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 514 -- test/test.js | 514 -- 43 files changed, 6206 insertions(+), 5136 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/benchmark.ndims.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (97%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/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 abe2ef8..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-10-01T05:13:39.953Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 740d5ce..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/maybe-broadcast-array) 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 4fadc31..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/maybe-broadcast-array) 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 a6e535a..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: '45 9 * * 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 + + ```
@@ -171,7 +164,7 @@ for ( i = 0; i < N; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -231,11 +224,11 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-maybe-broadcast-array/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor +[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor/tree/esm -[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes +[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 9763740..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,290 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var ndarrayBase = require( '@stdlib/ndarray-base-ctor' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArray = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::base_ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::base_ndarray,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( out.shape[ 0 ] !== shape[ 0 ] ) { - b.fail( 'unexpected result' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.ndims.js b/benchmark/benchmark.ndims.js deleted file mode 100644 index 1fa371b..0000000 --- a/benchmark/benchmark.ndims.js +++ /dev/null @@ -1,110 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var array = require( '@stdlib/ndarray-array' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} ndims - number of dimensions to which to broadcast -* @returns {Function} benchmark function -*/ -function createBenchmark( ndims ) { - var shape; - var sh; - var x; - var i; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - sh = x.shape; - - shape = []; - for ( i = 0; i < ndims; i++ ) { - shape.push( 0 ); - } - for ( i = ndims; i >= 1; i-- ) { - if ( i > shape.length ) { - shape[ ndims-i ] = 5; - } else { - shape[ ndims-i ] = sh[ i-1 ]; - } - } - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( x, shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var min; - var max; - var f; - var i; - - min = 2; - max = 10; - - for ( i = min; i <= max; i++ ) { - f = createBenchmark( i ); - bench( pkg+'::ndarray,2d:from_ndims=2,to_ndims='+i, f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index 90d11e3..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/maybe-broadcast-array" -%% click B href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/maybe-broadcast-array -[production-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 71859ce..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import maybeBroadcastArray from '../docs/types/index'; -export = maybeBroadcastArray; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 2ae3059..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var o=function(t,r){return function(){return r||t((r={exports:{}}).exports,r),r.exports}};var s=o(function(b,a){ -var u=require('@stdlib/ndarray-base-broadcast-array/dist');function c(t,r){var i,n,e;if(n=r.length,i=t.shape,i.length===n){for(e=0;e\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = arr.shape;\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nmodule.exports = maybeBroadcastArray;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape.\n*\n* @module @stdlib/ndarray-base-maybe-broadcast-array\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var maybeBroadcastArray = require( '@stdlib/ndarray-base-maybe-broadcast-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAY,QAAS,sCAAuC,EA8DhE,SAASC,EAAqBC,EAAKC,EAAQ,CAC1C,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAM,OACVC,EAAKF,EAAI,MAGJE,EAAG,SAAWC,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,CAAE,IAAMH,EAAOG,CAAE,EAEzB,OAAON,EAAWE,EAAKC,CAAM,EAG/B,OAAOD,CACR,CAEA,OAAOF,EAAWE,EAAKC,CAAM,CAC9B,CAKAJ,EAAO,QAAUE,IChDjB,IAAIM,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "broadcast", "maybeBroadcastArray", "arr", "shape", "sh", "N", "i", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 93528fb..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,74 +0,0 @@ - -{{alias}}( arr, shape ) - Broadcasts an ndarray to a specified shape if and only if the specified - shape differs from the provided ndarray's shape. - - If a provided ndarray has the same shape as the specified shape, the - function returns the provided ndarray. - - If a provided ndarray has a different (broadcast compatible) shape than the - specified shape, the function returns a new (base) ndarray view of the - provided ndarray's data. The view is typically **not** contiguous. As more - than one element of a returned view may refer to the same memory location, - writing to the view may affect multiple elements. If you need to write to - the returned array, copy the array before performing operations which may - mutate elements. - - A returned array is a view on the input array data buffer. The view is - typically *not* contiguous. As more than one element of a returned view may - refer to the same memory location, writing to the view may affect multiple - elements. If you need to write to the returned array, copy the array before - performing operations which may mutate elements. - - A returned array view is a "base" ndarray, and, thus, a returned array view - does not perform bounds checking or afford any of the guarantees of the non- - base ndarray constructor. The primary intent of this function is to - broadcast an ndarray-like object within internal implementations and to do - so with minimal overhead. - - The function throws an error if a provided ndarray is incompatible with a - provided shape. - - Parameters - ---------- - arr: ndarray - Input array. - - shape: ArrayLikeObject - Desired shape. - - Returns - ------- - out: ndarray - Broadcasted array. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > var sh = x.shape - [ 2, 2 ] - > var y = {{alias}}( x, [ 3, 2, 2 ] ) - - > sh = y.shape - [ 3, 2, 2 ] - > var v = y.get( 0, 0, 0 ) - 1 - > v = y.get( 0, 0, 1 ) - 2 - > v = y.get( 0, 1, 0 ) - 3 - > v = y.get( 0, 1, 1 ) - 4 - > v = y.get( 1, 0, 0 ) - 1 - > v = y.get( 1, 1, 0 ) - 3 - > v = y.get( 2, 0, 0 ) - 1 - > v = y.get( 2, 1, 1 ) - 4 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index d7a1a62..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,94 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ndarray } from '@stdlib/types/ndarray'; -import maybeBroadcastArray = require( './index' ); - -/** -* Mock function to create an ndarray-like object. -* -* @return ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns an ndarray... -{ - const x = array(); - - maybeBroadcastArray( x, [ 2, 2, 2 ] ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is not provided a first argument which is an ndarray... -{ - maybeBroadcastArray( '5', [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( 5, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( true, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( false, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( null, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( {}, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( [ '5' ], [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( ( x: number ): number => x, [ 2, 2, 2 ] ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a second argument which is an array-like object containing numbers... -{ - const x = array(); - - maybeBroadcastArray( x, '5' ); // $ExpectError - maybeBroadcastArray( x, 5 ); // $ExpectError - maybeBroadcastArray( x, true ); // $ExpectError - maybeBroadcastArray( x, false ); // $ExpectError - maybeBroadcastArray( x, null ); // $ExpectError - maybeBroadcastArray( x, {} ); // $ExpectError - maybeBroadcastArray( x, [ '5' ] ); // $ExpectError - maybeBroadcastArray( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - - maybeBroadcastArray(); // $ExpectError - maybeBroadcastArray( x ); // $ExpectError - maybeBroadcastArray( x, [ 1, 2, 3 ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index e787d6e..0000000 --- a/examples/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 array = require( '@stdlib/ndarray-array' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var maybeBroadcastArray = require( './../lib' ); - -// Create a 2x2 array: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -// returns - -// Broadcast the array to 3x2x2: -var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -// returns - -// Retrieve the shape: -var sh = y.shape; -// returns [ 3, 2, 2 ] - -// Retrieve the number of elements: -var N = numel( sh ); - -// Loop through the array elements... -var i; -for ( i = 0; i < N; i++ ) { - console.log( 'Y[%s] = %d', ind2sub( sh, i ).join( ', ' ), y.iget( i ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 97% rename from docs/types/index.d.ts rename to index.d.ts index 39826a4..679c9f1 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..15c5d13 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@esm/index.mjs";function t(t,e){var a,n,s;if(n=e.length,(a=t.shape).length===n){for(s=0;s\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = arr.shape;\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArray;\n"],"names":["maybeBroadcastArray","arr","shape","sh","N","i","length","broadcast"],"mappings":";;gGAoFA,SAASA,EAAqBC,EAAKC,GAClC,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAMI,QACVH,EAAKF,EAAIC,OAGDI,SAAWF,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,KAAQH,EAAOG,GAEvB,OAAOE,EAAWN,EAAKC,GAGzB,OAAOD,CACP,CAED,OAAOM,EAAWN,EAAKC,EACxB"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 834e930..0000000 --- a/lib/index.js +++ /dev/null @@ -1,68 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* @module @stdlib/ndarray-base-maybe-broadcast-array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var maybeBroadcastArray = require( '@stdlib/ndarray-base-maybe-broadcast-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -*/ - -// 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 278f868..0000000 --- a/lib/main.js +++ /dev/null @@ -1,111 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var broadcast = require( '@stdlib/ndarray-base-broadcast-array' ); - - -// MAIN // - -/** -* Broadcasts an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* ## Notes -* -* - If a provided ndarray has the same shape as the specified shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the specified shape, the function returns a new (base) ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to the view may affect multiple elements. If you need to write to the returned array, copy the array before performing operations which may mutate elements. -* -* @param {ndarray} arr - input array -* @param {NonNegativeIntegerArray} shape - desired shape -* @throws {Error} input array cannot have more dimensions than the desired shape -* @throws {Error} input array dimension sizes must be `1` or equal to the corresponding dimension in the provided shape -* @throws {Error} input array and desired shape must be broadcast compatible -* @returns {ndarray} broadcasted array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var y = maybeBroadcastArray( x, [ 3, 2 ] ); -* // throws -*/ -function maybeBroadcastArray( arr, shape ) { - var sh; - var N; - var i; - - N = shape.length; - sh = arr.shape; - - // Check whether we need to broadcast the input array... - if ( sh.length === N ) { - for ( i = 0; i < N; i++ ) { - // Check whether dimensions match... - if ( sh[ i ] !== shape[ i ] ) { - // We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape... - return broadcast( arr, shape ); - } - } - return arr; - } - // If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape... - return broadcast( arr, shape ); -} - - -// EXPORTS // - -module.exports = maybeBroadcastArray; diff --git a/package.json b/package.json index b362ea7..b74d597 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Broadcast an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's 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", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,39 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-base-broadcast-array": "^0.1.0", - "@stdlib/types": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.0" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.1.0", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/bench": "^0.1.0", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-base-ctor": "^0.1.0", - "@stdlib/ndarray-base-numel": "^0.1.0", - "@stdlib/ndarray-ctor": "^0.1.0", - "@stdlib/ndarray-ind2sub": "^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", @@ -85,9 +29,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..1a5becf --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index 8dadbc7..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,514 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 array = require( '@stdlib/ndarray-array' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var maybeBroadcastArray = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof maybeBroadcastArray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a desired shape which has fewer dimensions than the input array', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 ] - }); - - values = [ - [], - [ 2 ], - [ 2, 2 ], - [ 2, 2, 2 ], - [ 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2, 2, 2 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided a shape with '+values[ i ].length+' dimension' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape having a dimension whose size is less than the corresponding dimension in the input array', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 10, 1 ], - [ 10, 10, 2 ], - [ 10, 10, 9 ], - [ 10, 1, 10 ], - [ 10, 2, 10 ], - [ 10, 9, 10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape and an input array shape which are broadcast-incompatible', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 20, 10 ], - [ 10, 10, 100 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function returns a "base" ndarray instance', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = maybeBroadcastArray( x, [ 2, 2, 2 ] ); - - t.notEqual( y, x, 'returns new instance' ); - t.strictEqual( y instanceof ndarray, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view over the input array data buffer', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = maybeBroadcastArray( x, [ 2, 2, 2 ] ); - - t.strictEqual( y.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; strides)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, -1 ], 3, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; strides)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, 1 ], 2, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; non-contiguous)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ 4, 2 ], 1, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 5 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 7 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (column-major)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'column-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (same shape)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2, 2 ], - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - // Should return the same instance: - t.strictEqual( y, x, 'returns expected value' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 1, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 1, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (same number of dimensions)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1, 2 ], - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (singleton dimension)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (singleton dimension)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 1, 2 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (0-dimensional array)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1 ]; - x = ndarray( 'generic', data, [], [ 0 ], 0, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 7e8e63f..0000000 --- a/test/test.js +++ /dev/null @@ -1,514 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 array = require( '@stdlib/ndarray-array' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var maybeBroadcastArray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof maybeBroadcastArray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a desired shape which has fewer dimensions than the input array', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 ] - }); - - values = [ - [], - [ 2 ], - [ 2, 2 ], - [ 2, 2, 2 ], - [ 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2, 2, 2 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided a shape with '+values[ i ].length+' dimension' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape having a dimension whose size is less than the corresponding dimension in the input array', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 10, 1 ], - [ 10, 10, 2 ], - [ 10, 10, 9 ], - [ 10, 1, 10 ], - [ 10, 2, 10 ], - [ 10, 9, 10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape and an input array shape which are broadcast-incompatible', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 20, 10 ], - [ 10, 10, 100 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function returns a "base" ndarray instance', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = maybeBroadcastArray( x, [ 2, 2, 2 ] ); - - t.notEqual( y, x, 'returns new instance' ); - t.strictEqual( y instanceof ndarray, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view over the input array data buffer', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = maybeBroadcastArray( x, [ 2, 2, 2 ] ); - - t.strictEqual( y.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; strides)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, -1 ], 3, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; strides)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, 1 ], 2, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; non-contiguous)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ 4, 2 ], 1, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 5 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 7 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (column-major)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'column-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (same shape)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2, 2 ], - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - // Should return the same instance: - t.strictEqual( y, x, 'returns expected value' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 1, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 1, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (same number of dimensions)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1, 2 ], - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (singleton dimension)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (singleton dimension)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 1, 2 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (0-dimensional array)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1 ]; - x = ndarray( 'generic', data, [], [ 0 ], 0, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); From 511795a532cc3f0c61c2a9ec08192fe384f9e1d2 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 5 Oct 2023 19:30:35 +0000 Subject: [PATCH 040/119] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 1f5e116..9136f63 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ }, "dependencies": { "@stdlib/ndarray-base-broadcast-array": "^0.1.0", - "@stdlib/types": "^0.1.0" + "@stdlib/types": "^0.1.0", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1" }, "devDependencies": { "@stdlib/array-float64": "^0.1.0", @@ -89,4 +90,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From f5734520e9d5cedbb97d30d0db144935aa63d6fd Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 7 Oct 2023 02:27:15 +0000 Subject: [PATCH 041/119] Remove files --- index.d.ts | 81 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6263 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 679c9f1..0000000 --- a/index.d.ts +++ /dev/null @@ -1,81 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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'; -import { ndarray } from '@stdlib/types/ndarray'; - -/** -* Broadcasts an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* ## Notes -* -* - The function throws an error if a provided ndarray is incompatible with a provided shape. -* - If a provided ndarray has the same shape as the specified shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the specified shape, the function returns a new (base) ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to the view may affect multiple elements. If you need to write to the returned array, copy the array before performing operations which may mutate elements. -* - A returned array view is a "base" ndarray, and, thus, a returned array view does not perform bounds checking or afford any of the guarantees of the non-base ndarray constructor. The primary intent of this function is to broadcast an ndarray-like object within internal implementations and to do so with minimal overhead. -* -* @param arr - input array -* @param shape - desired shape -* @throws input array cannot have more dimensions than the desired shape -* @throws input array dimension sizes must be `1` or equal to the corresponding dimension in the provided shape -* @throws input array and desired shape must be broadcast compatible -* @returns broadcasted array -* -* @example -* var array = require( `@stdlib/ndarray/array` ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -*/ -declare function maybeBroadcastArray( arr: ndarray, shape: ArrayLike ): ndarray; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = maybeBroadcastArray; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 15c5d13..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@esm/index.mjs";function t(t,e){var a,n,s;if(n=e.length,(a=t.shape).length===n){for(s=0;s\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = arr.shape;\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArray;\n"],"names":["maybeBroadcastArray","arr","shape","sh","N","i","length","broadcast"],"mappings":";;gGAoFA,SAASA,EAAqBC,EAAKC,GAClC,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAMI,QACVH,EAAKF,EAAIC,OAGDI,SAAWF,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,KAAQH,EAAOG,GAEvB,OAAOE,EAAWN,EAAKC,GAGzB,OAAOD,CACP,CAED,OAAOM,EAAWN,EAAKC,EACxB"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 1a5becf..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 15d3155be4104c4d4604456be0cd381b434637f7 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 7 Oct 2023 02:28:22 +0000 Subject: [PATCH 042/119] 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 | 47 +- benchmark/benchmark.js | 290 - benchmark/benchmark.ndims.js | 110 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 74 - docs/types/test.ts | 94 - examples/index.js | 45 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 68 - lib/main.js | 111 - package.json | 63 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 514 -- test/test.js | 514 -- 42 files changed, 6206 insertions(+), 5135 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/benchmark.ndims.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (97%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/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 740d5ce..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/maybe-broadcast-array) 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 4fadc31..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/maybe-broadcast-array) 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 a6e535a..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: '45 9 * * 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 + + ```
@@ -171,7 +164,7 @@ for ( i = 0; i < N; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -231,11 +224,11 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-maybe-broadcast-array/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor +[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor/tree/esm -[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes +[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 9763740..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,290 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var ndarrayBase = require( '@stdlib/ndarray-base-ctor' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArray = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::base_ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::base_ndarray,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( out.shape[ 0 ] !== shape[ 0 ] ) { - b.fail( 'unexpected result' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.ndims.js b/benchmark/benchmark.ndims.js deleted file mode 100644 index 1fa371b..0000000 --- a/benchmark/benchmark.ndims.js +++ /dev/null @@ -1,110 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var array = require( '@stdlib/ndarray-array' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} ndims - number of dimensions to which to broadcast -* @returns {Function} benchmark function -*/ -function createBenchmark( ndims ) { - var shape; - var sh; - var x; - var i; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - sh = x.shape; - - shape = []; - for ( i = 0; i < ndims; i++ ) { - shape.push( 0 ); - } - for ( i = ndims; i >= 1; i-- ) { - if ( i > shape.length ) { - shape[ ndims-i ] = 5; - } else { - shape[ ndims-i ] = sh[ i-1 ]; - } - } - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( x, shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var min; - var max; - var f; - var i; - - min = 2; - max = 10; - - for ( i = min; i <= max; i++ ) { - f = createBenchmark( i ); - bench( pkg+'::ndarray,2d:from_ndims=2,to_ndims='+i, f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index 90d11e3..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/maybe-broadcast-array" -%% click B href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/maybe-broadcast-array -[production-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 71859ce..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import maybeBroadcastArray from '../docs/types/index'; -export = maybeBroadcastArray; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 2ae3059..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var o=function(t,r){return function(){return r||t((r={exports:{}}).exports,r),r.exports}};var s=o(function(b,a){ -var u=require('@stdlib/ndarray-base-broadcast-array/dist');function c(t,r){var i,n,e;if(n=r.length,i=t.shape,i.length===n){for(e=0;e\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = arr.shape;\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nmodule.exports = maybeBroadcastArray;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape.\n*\n* @module @stdlib/ndarray-base-maybe-broadcast-array\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var maybeBroadcastArray = require( '@stdlib/ndarray-base-maybe-broadcast-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAY,QAAS,sCAAuC,EA8DhE,SAASC,EAAqBC,EAAKC,EAAQ,CAC1C,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAM,OACVC,EAAKF,EAAI,MAGJE,EAAG,SAAWC,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,CAAE,IAAMH,EAAOG,CAAE,EAEzB,OAAON,EAAWE,EAAKC,CAAM,EAG/B,OAAOD,CACR,CAEA,OAAOF,EAAWE,EAAKC,CAAM,CAC9B,CAKAJ,EAAO,QAAUE,IChDjB,IAAIM,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "broadcast", "maybeBroadcastArray", "arr", "shape", "sh", "N", "i", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 93528fb..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,74 +0,0 @@ - -{{alias}}( arr, shape ) - Broadcasts an ndarray to a specified shape if and only if the specified - shape differs from the provided ndarray's shape. - - If a provided ndarray has the same shape as the specified shape, the - function returns the provided ndarray. - - If a provided ndarray has a different (broadcast compatible) shape than the - specified shape, the function returns a new (base) ndarray view of the - provided ndarray's data. The view is typically **not** contiguous. As more - than one element of a returned view may refer to the same memory location, - writing to the view may affect multiple elements. If you need to write to - the returned array, copy the array before performing operations which may - mutate elements. - - A returned array is a view on the input array data buffer. The view is - typically *not* contiguous. As more than one element of a returned view may - refer to the same memory location, writing to the view may affect multiple - elements. If you need to write to the returned array, copy the array before - performing operations which may mutate elements. - - A returned array view is a "base" ndarray, and, thus, a returned array view - does not perform bounds checking or afford any of the guarantees of the non- - base ndarray constructor. The primary intent of this function is to - broadcast an ndarray-like object within internal implementations and to do - so with minimal overhead. - - The function throws an error if a provided ndarray is incompatible with a - provided shape. - - Parameters - ---------- - arr: ndarray - Input array. - - shape: ArrayLikeObject - Desired shape. - - Returns - ------- - out: ndarray - Broadcasted array. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > var sh = x.shape - [ 2, 2 ] - > var y = {{alias}}( x, [ 3, 2, 2 ] ) - - > sh = y.shape - [ 3, 2, 2 ] - > var v = y.get( 0, 0, 0 ) - 1 - > v = y.get( 0, 0, 1 ) - 2 - > v = y.get( 0, 1, 0 ) - 3 - > v = y.get( 0, 1, 1 ) - 4 - > v = y.get( 1, 0, 0 ) - 1 - > v = y.get( 1, 1, 0 ) - 3 - > v = y.get( 2, 0, 0 ) - 1 - > v = y.get( 2, 1, 1 ) - 4 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index d7a1a62..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,94 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ndarray } from '@stdlib/types/ndarray'; -import maybeBroadcastArray = require( './index' ); - -/** -* Mock function to create an ndarray-like object. -* -* @return ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns an ndarray... -{ - const x = array(); - - maybeBroadcastArray( x, [ 2, 2, 2 ] ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is not provided a first argument which is an ndarray... -{ - maybeBroadcastArray( '5', [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( 5, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( true, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( false, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( null, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( {}, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( [ '5' ], [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( ( x: number ): number => x, [ 2, 2, 2 ] ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a second argument which is an array-like object containing numbers... -{ - const x = array(); - - maybeBroadcastArray( x, '5' ); // $ExpectError - maybeBroadcastArray( x, 5 ); // $ExpectError - maybeBroadcastArray( x, true ); // $ExpectError - maybeBroadcastArray( x, false ); // $ExpectError - maybeBroadcastArray( x, null ); // $ExpectError - maybeBroadcastArray( x, {} ); // $ExpectError - maybeBroadcastArray( x, [ '5' ] ); // $ExpectError - maybeBroadcastArray( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - - maybeBroadcastArray(); // $ExpectError - maybeBroadcastArray( x ); // $ExpectError - maybeBroadcastArray( x, [ 1, 2, 3 ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index e787d6e..0000000 --- a/examples/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 array = require( '@stdlib/ndarray-array' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var maybeBroadcastArray = require( './../lib' ); - -// Create a 2x2 array: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -// returns - -// Broadcast the array to 3x2x2: -var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -// returns - -// Retrieve the shape: -var sh = y.shape; -// returns [ 3, 2, 2 ] - -// Retrieve the number of elements: -var N = numel( sh ); - -// Loop through the array elements... -var i; -for ( i = 0; i < N; i++ ) { - console.log( 'Y[%s] = %d', ind2sub( sh, i ).join( ', ' ), y.iget( i ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 97% rename from docs/types/index.d.ts rename to index.d.ts index 39826a4..679c9f1 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..15c5d13 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@esm/index.mjs";function t(t,e){var a,n,s;if(n=e.length,(a=t.shape).length===n){for(s=0;s\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = arr.shape;\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArray;\n"],"names":["maybeBroadcastArray","arr","shape","sh","N","i","length","broadcast"],"mappings":";;gGAoFA,SAASA,EAAqBC,EAAKC,GAClC,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAMI,QACVH,EAAKF,EAAIC,OAGDI,SAAWF,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,KAAQH,EAAOG,GAEvB,OAAOE,EAAWN,EAAKC,GAGzB,OAAOD,CACP,CAED,OAAOM,EAAWN,EAAKC,EACxB"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 834e930..0000000 --- a/lib/index.js +++ /dev/null @@ -1,68 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* @module @stdlib/ndarray-base-maybe-broadcast-array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var maybeBroadcastArray = require( '@stdlib/ndarray-base-maybe-broadcast-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -*/ - -// 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 278f868..0000000 --- a/lib/main.js +++ /dev/null @@ -1,111 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var broadcast = require( '@stdlib/ndarray-base-broadcast-array' ); - - -// MAIN // - -/** -* Broadcasts an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* ## Notes -* -* - If a provided ndarray has the same shape as the specified shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the specified shape, the function returns a new (base) ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to the view may affect multiple elements. If you need to write to the returned array, copy the array before performing operations which may mutate elements. -* -* @param {ndarray} arr - input array -* @param {NonNegativeIntegerArray} shape - desired shape -* @throws {Error} input array cannot have more dimensions than the desired shape -* @throws {Error} input array dimension sizes must be `1` or equal to the corresponding dimension in the provided shape -* @throws {Error} input array and desired shape must be broadcast compatible -* @returns {ndarray} broadcasted array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var y = maybeBroadcastArray( x, [ 3, 2 ] ); -* // throws -*/ -function maybeBroadcastArray( arr, shape ) { - var sh; - var N; - var i; - - N = shape.length; - sh = arr.shape; - - // Check whether we need to broadcast the input array... - if ( sh.length === N ) { - for ( i = 0; i < N; i++ ) { - // Check whether dimensions match... - if ( sh[ i ] !== shape[ i ] ) { - // We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape... - return broadcast( arr, shape ); - } - } - return arr; - } - // If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape... - return broadcast( arr, shape ); -} - - -// EXPORTS // - -module.exports = maybeBroadcastArray; diff --git a/package.json b/package.json index 9136f63..b74d597 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Broadcast an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's 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", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,39 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-base-broadcast-array": "^0.1.0", - "@stdlib/types": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.1.0", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/bench": "^0.1.0", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-base-ctor": "^0.1.0", - "@stdlib/ndarray-base-numel": "^0.1.1", - "@stdlib/ndarray-ctor": "^0.1.0", - "@stdlib/ndarray-ind2sub": "^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", @@ -85,9 +29,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..7ea70b6 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index 8dadbc7..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,514 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 array = require( '@stdlib/ndarray-array' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var maybeBroadcastArray = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof maybeBroadcastArray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a desired shape which has fewer dimensions than the input array', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 ] - }); - - values = [ - [], - [ 2 ], - [ 2, 2 ], - [ 2, 2, 2 ], - [ 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2, 2, 2 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided a shape with '+values[ i ].length+' dimension' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape having a dimension whose size is less than the corresponding dimension in the input array', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 10, 1 ], - [ 10, 10, 2 ], - [ 10, 10, 9 ], - [ 10, 1, 10 ], - [ 10, 2, 10 ], - [ 10, 9, 10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape and an input array shape which are broadcast-incompatible', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 20, 10 ], - [ 10, 10, 100 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function returns a "base" ndarray instance', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = maybeBroadcastArray( x, [ 2, 2, 2 ] ); - - t.notEqual( y, x, 'returns new instance' ); - t.strictEqual( y instanceof ndarray, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view over the input array data buffer', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = maybeBroadcastArray( x, [ 2, 2, 2 ] ); - - t.strictEqual( y.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; strides)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, -1 ], 3, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; strides)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, 1 ], 2, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; non-contiguous)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ 4, 2 ], 1, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 5 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 7 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (column-major)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'column-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (same shape)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2, 2 ], - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - // Should return the same instance: - t.strictEqual( y, x, 'returns expected value' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 1, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 1, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (same number of dimensions)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1, 2 ], - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (singleton dimension)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (singleton dimension)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 1, 2 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (0-dimensional array)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1 ]; - x = ndarray( 'generic', data, [], [ 0 ], 0, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 7e8e63f..0000000 --- a/test/test.js +++ /dev/null @@ -1,514 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 array = require( '@stdlib/ndarray-array' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var maybeBroadcastArray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof maybeBroadcastArray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a desired shape which has fewer dimensions than the input array', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 ] - }); - - values = [ - [], - [ 2 ], - [ 2, 2 ], - [ 2, 2, 2 ], - [ 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2, 2, 2 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided a shape with '+values[ i ].length+' dimension' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape having a dimension whose size is less than the corresponding dimension in the input array', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 10, 1 ], - [ 10, 10, 2 ], - [ 10, 10, 9 ], - [ 10, 1, 10 ], - [ 10, 2, 10 ], - [ 10, 9, 10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape and an input array shape which are broadcast-incompatible', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 20, 10 ], - [ 10, 10, 100 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function returns a "base" ndarray instance', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = maybeBroadcastArray( x, [ 2, 2, 2 ] ); - - t.notEqual( y, x, 'returns new instance' ); - t.strictEqual( y instanceof ndarray, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view over the input array data buffer', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = maybeBroadcastArray( x, [ 2, 2, 2 ] ); - - t.strictEqual( y.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; strides)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, -1 ], 3, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; strides)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, 1 ], 2, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; non-contiguous)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ 4, 2 ], 1, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 5 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 7 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (column-major)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'column-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (same shape)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2, 2 ], - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - // Should return the same instance: - t.strictEqual( y, x, 'returns expected value' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 1, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 1, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (same number of dimensions)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1, 2 ], - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (singleton dimension)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (singleton dimension)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 1, 2 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (0-dimensional array)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1 ]; - x = ndarray( 'generic', data, [], [ 0 ], 0, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); From 65e957421b51469a3868c46548394b960892be47 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 7 Oct 2023 10:17:42 +0000 Subject: [PATCH 043/119] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 1f5e116..9136f63 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ }, "dependencies": { "@stdlib/ndarray-base-broadcast-array": "^0.1.0", - "@stdlib/types": "^0.1.0" + "@stdlib/types": "^0.1.0", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1" }, "devDependencies": { "@stdlib/array-float64": "^0.1.0", @@ -89,4 +90,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From 4c92117a665ad5bead72a469d4fc1993da463915 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 7 Oct 2023 14:23:09 +0000 Subject: [PATCH 044/119] Remove files --- index.d.ts | 81 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6263 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 679c9f1..0000000 --- a/index.d.ts +++ /dev/null @@ -1,81 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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'; -import { ndarray } from '@stdlib/types/ndarray'; - -/** -* Broadcasts an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* ## Notes -* -* - The function throws an error if a provided ndarray is incompatible with a provided shape. -* - If a provided ndarray has the same shape as the specified shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the specified shape, the function returns a new (base) ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to the view may affect multiple elements. If you need to write to the returned array, copy the array before performing operations which may mutate elements. -* - A returned array view is a "base" ndarray, and, thus, a returned array view does not perform bounds checking or afford any of the guarantees of the non-base ndarray constructor. The primary intent of this function is to broadcast an ndarray-like object within internal implementations and to do so with minimal overhead. -* -* @param arr - input array -* @param shape - desired shape -* @throws input array cannot have more dimensions than the desired shape -* @throws input array dimension sizes must be `1` or equal to the corresponding dimension in the provided shape -* @throws input array and desired shape must be broadcast compatible -* @returns broadcasted array -* -* @example -* var array = require( `@stdlib/ndarray/array` ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -*/ -declare function maybeBroadcastArray( arr: ndarray, shape: ArrayLike ): ndarray; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = maybeBroadcastArray; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 15c5d13..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@esm/index.mjs";function t(t,e){var a,n,s;if(n=e.length,(a=t.shape).length===n){for(s=0;s\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = arr.shape;\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArray;\n"],"names":["maybeBroadcastArray","arr","shape","sh","N","i","length","broadcast"],"mappings":";;gGAoFA,SAASA,EAAqBC,EAAKC,GAClC,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAMI,QACVH,EAAKF,EAAIC,OAGDI,SAAWF,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,KAAQH,EAAOG,GAEvB,OAAOE,EAAWN,EAAKC,GAGzB,OAAOD,CACP,CAED,OAAOM,EAAWN,EAAKC,EACxB"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 7ea70b6..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 90dbea327d52da98c81794b65b51ee925321a37f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 7 Oct 2023 14:24:16 +0000 Subject: [PATCH 045/119] 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 | 47 +- benchmark/benchmark.js | 290 - benchmark/benchmark.ndims.js | 110 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 68 - docs/types/test.ts | 94 - examples/index.js | 45 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 68 - lib/main.js | 111 - package.json | 63 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 514 -- test/test.js | 514 -- 42 files changed, 6206 insertions(+), 5129 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.ndims.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (97%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/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 740d5ce..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/maybe-broadcast-array) 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 4fadc31..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/maybe-broadcast-array) 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 a6e535a..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: '45 9 * * 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 + + ```
@@ -171,7 +164,7 @@ for ( i = 0; i < N; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -231,11 +224,11 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-maybe-broadcast-array/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor +[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor/tree/esm -[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes +[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 9763740..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,290 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var ndarrayBase = require( '@stdlib/ndarray-base-ctor' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArray = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::base_ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::base_ndarray,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( out.shape[ 0 ] !== shape[ 0 ] ) { - b.fail( 'unexpected result' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.ndims.js b/benchmark/benchmark.ndims.js deleted file mode 100644 index b92220c..0000000 --- a/benchmark/benchmark.ndims.js +++ /dev/null @@ -1,110 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var array = require( '@stdlib/ndarray-array' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} ndims - number of dimensions to which to broadcast -* @returns {Function} benchmark function -*/ -function createBenchmark( ndims ) { - var shape; - var sh; - var x; - var i; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - sh = x.shape; - - shape = []; - for ( i = 0; i < ndims; i++ ) { - shape.push( 0 ); - } - for ( i = ndims; i >= 1; i-- ) { - if ( i > sh.length ) { - shape[ ndims-i ] = 5; - } else { - shape[ ndims-i ] = sh[ i-1 ]; - } - } - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( x, shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var min; - var max; - var f; - var i; - - min = 2; - max = 10; - - for ( i = min; i <= max; i++ ) { - f = createBenchmark( i ); - bench( pkg+'::ndarray,2d:from_ndims=2,to_ndims='+i, f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index 90d11e3..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/maybe-broadcast-array" -%% click B href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/maybe-broadcast-array -[production-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 71859ce..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import maybeBroadcastArray from '../docs/types/index'; -export = maybeBroadcastArray; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 2ae3059..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var o=function(t,r){return function(){return r||t((r={exports:{}}).exports,r),r.exports}};var s=o(function(b,a){ -var u=require('@stdlib/ndarray-base-broadcast-array/dist');function c(t,r){var i,n,e;if(n=r.length,i=t.shape,i.length===n){for(e=0;e\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = arr.shape;\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nmodule.exports = maybeBroadcastArray;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape.\n*\n* @module @stdlib/ndarray-base-maybe-broadcast-array\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var maybeBroadcastArray = require( '@stdlib/ndarray-base-maybe-broadcast-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAY,QAAS,sCAAuC,EA8DhE,SAASC,EAAqBC,EAAKC,EAAQ,CAC1C,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAM,OACVC,EAAKF,EAAI,MAGJE,EAAG,SAAWC,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,CAAE,IAAMH,EAAOG,CAAE,EAEzB,OAAON,EAAWE,EAAKC,CAAM,EAG/B,OAAOD,CACR,CAEA,OAAOF,EAAWE,EAAKC,CAAM,CAC9B,CAKAJ,EAAO,QAAUE,IChDjB,IAAIM,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "broadcast", "maybeBroadcastArray", "arr", "shape", "sh", "N", "i", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 01ecba8..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,68 +0,0 @@ - -{{alias}}( arr, shape ) - Broadcasts an ndarray to a specified shape if and only if the specified - shape differs from the provided ndarray's shape. - - If a provided ndarray has the same shape as the specified shape, the - function returns the provided ndarray. - - If a provided ndarray has a different (broadcast compatible) shape than the - specified shape, the function returns a new (base) ndarray view of the - provided ndarray's data. The view is typically **not** contiguous. As more - than one element of a returned view may refer to the same memory location, - writing to the view may affect multiple elements. If you need to write to - the returned array, copy the array before performing operations which may - mutate elements. - - A returned array view is a "base" ndarray, and, thus, a returned array view - does not perform bounds checking or afford any of the guarantees of the non- - base ndarray constructor. The primary intent of this function is to - broadcast an ndarray-like object within internal implementations and to do - so with minimal overhead. - - The function throws an error if a provided ndarray is incompatible with a - provided shape. - - Parameters - ---------- - arr: ndarray - Input array. - - shape: ArrayLikeObject - Desired shape. - - Returns - ------- - out: ndarray - Broadcasted array. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > var sh = x.shape - [ 2, 2 ] - > var y = {{alias}}( x, [ 3, 2, 2 ] ) - - > sh = y.shape - [ 3, 2, 2 ] - > var v = y.get( 0, 0, 0 ) - 1 - > v = y.get( 0, 0, 1 ) - 2 - > v = y.get( 0, 1, 0 ) - 3 - > v = y.get( 0, 1, 1 ) - 4 - > v = y.get( 1, 0, 0 ) - 1 - > v = y.get( 1, 1, 0 ) - 3 - > v = y.get( 2, 0, 0 ) - 1 - > v = y.get( 2, 1, 1 ) - 4 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index d7a1a62..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,94 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ndarray } from '@stdlib/types/ndarray'; -import maybeBroadcastArray = require( './index' ); - -/** -* Mock function to create an ndarray-like object. -* -* @return ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns an ndarray... -{ - const x = array(); - - maybeBroadcastArray( x, [ 2, 2, 2 ] ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is not provided a first argument which is an ndarray... -{ - maybeBroadcastArray( '5', [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( 5, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( true, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( false, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( null, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( {}, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( [ '5' ], [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( ( x: number ): number => x, [ 2, 2, 2 ] ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a second argument which is an array-like object containing numbers... -{ - const x = array(); - - maybeBroadcastArray( x, '5' ); // $ExpectError - maybeBroadcastArray( x, 5 ); // $ExpectError - maybeBroadcastArray( x, true ); // $ExpectError - maybeBroadcastArray( x, false ); // $ExpectError - maybeBroadcastArray( x, null ); // $ExpectError - maybeBroadcastArray( x, {} ); // $ExpectError - maybeBroadcastArray( x, [ '5' ] ); // $ExpectError - maybeBroadcastArray( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - - maybeBroadcastArray(); // $ExpectError - maybeBroadcastArray( x ); // $ExpectError - maybeBroadcastArray( x, [ 1, 2, 3 ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index e787d6e..0000000 --- a/examples/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 array = require( '@stdlib/ndarray-array' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var maybeBroadcastArray = require( './../lib' ); - -// Create a 2x2 array: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -// returns - -// Broadcast the array to 3x2x2: -var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -// returns - -// Retrieve the shape: -var sh = y.shape; -// returns [ 3, 2, 2 ] - -// Retrieve the number of elements: -var N = numel( sh ); - -// Loop through the array elements... -var i; -for ( i = 0; i < N; i++ ) { - console.log( 'Y[%s] = %d', ind2sub( sh, i ).join( ', ' ), y.iget( i ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 97% rename from docs/types/index.d.ts rename to index.d.ts index 39826a4..679c9f1 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..15c5d13 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@esm/index.mjs";function t(t,e){var a,n,s;if(n=e.length,(a=t.shape).length===n){for(s=0;s\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = arr.shape;\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArray;\n"],"names":["maybeBroadcastArray","arr","shape","sh","N","i","length","broadcast"],"mappings":";;gGAoFA,SAASA,EAAqBC,EAAKC,GAClC,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAMI,QACVH,EAAKF,EAAIC,OAGDI,SAAWF,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,KAAQH,EAAOG,GAEvB,OAAOE,EAAWN,EAAKC,GAGzB,OAAOD,CACP,CAED,OAAOM,EAAWN,EAAKC,EACxB"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 834e930..0000000 --- a/lib/index.js +++ /dev/null @@ -1,68 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* @module @stdlib/ndarray-base-maybe-broadcast-array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var maybeBroadcastArray = require( '@stdlib/ndarray-base-maybe-broadcast-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -*/ - -// 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 278f868..0000000 --- a/lib/main.js +++ /dev/null @@ -1,111 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var broadcast = require( '@stdlib/ndarray-base-broadcast-array' ); - - -// MAIN // - -/** -* Broadcasts an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* ## Notes -* -* - If a provided ndarray has the same shape as the specified shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the specified shape, the function returns a new (base) ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to the view may affect multiple elements. If you need to write to the returned array, copy the array before performing operations which may mutate elements. -* -* @param {ndarray} arr - input array -* @param {NonNegativeIntegerArray} shape - desired shape -* @throws {Error} input array cannot have more dimensions than the desired shape -* @throws {Error} input array dimension sizes must be `1` or equal to the corresponding dimension in the provided shape -* @throws {Error} input array and desired shape must be broadcast compatible -* @returns {ndarray} broadcasted array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var y = maybeBroadcastArray( x, [ 3, 2 ] ); -* // throws -*/ -function maybeBroadcastArray( arr, shape ) { - var sh; - var N; - var i; - - N = shape.length; - sh = arr.shape; - - // Check whether we need to broadcast the input array... - if ( sh.length === N ) { - for ( i = 0; i < N; i++ ) { - // Check whether dimensions match... - if ( sh[ i ] !== shape[ i ] ) { - // We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape... - return broadcast( arr, shape ); - } - } - return arr; - } - // If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape... - return broadcast( arr, shape ); -} - - -// EXPORTS // - -module.exports = maybeBroadcastArray; diff --git a/package.json b/package.json index 9136f63..b74d597 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Broadcast an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's 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", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,39 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-base-broadcast-array": "^0.1.0", - "@stdlib/types": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.1.0", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/bench": "^0.1.0", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-base-ctor": "^0.1.0", - "@stdlib/ndarray-base-numel": "^0.1.1", - "@stdlib/ndarray-ctor": "^0.1.0", - "@stdlib/ndarray-ind2sub": "^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", @@ -85,9 +29,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..a14af41 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index 8dadbc7..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,514 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 array = require( '@stdlib/ndarray-array' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var maybeBroadcastArray = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof maybeBroadcastArray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a desired shape which has fewer dimensions than the input array', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 ] - }); - - values = [ - [], - [ 2 ], - [ 2, 2 ], - [ 2, 2, 2 ], - [ 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2, 2, 2 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided a shape with '+values[ i ].length+' dimension' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape having a dimension whose size is less than the corresponding dimension in the input array', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 10, 1 ], - [ 10, 10, 2 ], - [ 10, 10, 9 ], - [ 10, 1, 10 ], - [ 10, 2, 10 ], - [ 10, 9, 10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape and an input array shape which are broadcast-incompatible', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 20, 10 ], - [ 10, 10, 100 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function returns a "base" ndarray instance', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = maybeBroadcastArray( x, [ 2, 2, 2 ] ); - - t.notEqual( y, x, 'returns new instance' ); - t.strictEqual( y instanceof ndarray, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view over the input array data buffer', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = maybeBroadcastArray( x, [ 2, 2, 2 ] ); - - t.strictEqual( y.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; strides)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, -1 ], 3, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; strides)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, 1 ], 2, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; non-contiguous)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ 4, 2 ], 1, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 5 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 7 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (column-major)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'column-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (same shape)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2, 2 ], - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - // Should return the same instance: - t.strictEqual( y, x, 'returns expected value' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 1, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 1, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (same number of dimensions)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1, 2 ], - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (singleton dimension)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (singleton dimension)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 1, 2 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (0-dimensional array)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1 ]; - x = ndarray( 'generic', data, [], [ 0 ], 0, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 7e8e63f..0000000 --- a/test/test.js +++ /dev/null @@ -1,514 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 array = require( '@stdlib/ndarray-array' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var maybeBroadcastArray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof maybeBroadcastArray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a desired shape which has fewer dimensions than the input array', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 ] - }); - - values = [ - [], - [ 2 ], - [ 2, 2 ], - [ 2, 2, 2 ], - [ 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2, 2, 2 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided a shape with '+values[ i ].length+' dimension' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape having a dimension whose size is less than the corresponding dimension in the input array', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 10, 1 ], - [ 10, 10, 2 ], - [ 10, 10, 9 ], - [ 10, 1, 10 ], - [ 10, 2, 10 ], - [ 10, 9, 10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape and an input array shape which are broadcast-incompatible', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 20, 10 ], - [ 10, 10, 100 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function returns a "base" ndarray instance', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = maybeBroadcastArray( x, [ 2, 2, 2 ] ); - - t.notEqual( y, x, 'returns new instance' ); - t.strictEqual( y instanceof ndarray, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view over the input array data buffer', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = maybeBroadcastArray( x, [ 2, 2, 2 ] ); - - t.strictEqual( y.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; strides)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, -1 ], 3, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; strides)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, 1 ], 2, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; non-contiguous)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ 4, 2 ], 1, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 5 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 7 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (column-major)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'column-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (same shape)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2, 2 ], - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - // Should return the same instance: - t.strictEqual( y, x, 'returns expected value' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 1, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 1, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (same number of dimensions)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1, 2 ], - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (singleton dimension)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (singleton dimension)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 1, 2 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (0-dimensional array)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1 ]; - x = ndarray( 'generic', data, [], [ 0 ], 0, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); From e7ed0fc9391f38d1d8d14e9e3c35e55bdbdda7f0 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 8 Oct 2023 19:14:10 +0000 Subject: [PATCH 046/119] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 15821ed..e0fed1c 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,8 @@ "dependencies": { "@stdlib/ndarray-base-broadcast-array": "^0.1.0", "@stdlib/ndarray-base-shape": "github:stdlib-js/ndarray-base-shape#main", - "@stdlib/types": "^0.1.0" + "@stdlib/types": "^0.1.0", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1" }, "devDependencies": { "@stdlib/array-float64": "^0.1.0", @@ -90,4 +91,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From 641bc16ab21d594de748c9a311d4beb27e509a9d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 8 Oct 2023 19:14:43 +0000 Subject: [PATCH 047/119] Remove files --- index.d.ts | 81 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6263 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 679c9f1..0000000 --- a/index.d.ts +++ /dev/null @@ -1,81 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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'; -import { ndarray } from '@stdlib/types/ndarray'; - -/** -* Broadcasts an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* ## Notes -* -* - The function throws an error if a provided ndarray is incompatible with a provided shape. -* - If a provided ndarray has the same shape as the specified shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the specified shape, the function returns a new (base) ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to the view may affect multiple elements. If you need to write to the returned array, copy the array before performing operations which may mutate elements. -* - A returned array view is a "base" ndarray, and, thus, a returned array view does not perform bounds checking or afford any of the guarantees of the non-base ndarray constructor. The primary intent of this function is to broadcast an ndarray-like object within internal implementations and to do so with minimal overhead. -* -* @param arr - input array -* @param shape - desired shape -* @throws input array cannot have more dimensions than the desired shape -* @throws input array dimension sizes must be `1` or equal to the corresponding dimension in the provided shape -* @throws input array and desired shape must be broadcast compatible -* @returns broadcasted array -* -* @example -* var array = require( `@stdlib/ndarray/array` ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -*/ -declare function maybeBroadcastArray( arr: ndarray, shape: ArrayLike ): ndarray; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = maybeBroadcastArray; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 15c5d13..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@esm/index.mjs";function t(t,e){var a,n,s;if(n=e.length,(a=t.shape).length===n){for(s=0;s\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = arr.shape;\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArray;\n"],"names":["maybeBroadcastArray","arr","shape","sh","N","i","length","broadcast"],"mappings":";;gGAoFA,SAASA,EAAqBC,EAAKC,GAClC,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAMI,QACVH,EAAKF,EAAIC,OAGDI,SAAWF,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,KAAQH,EAAOG,GAEvB,OAAOE,EAAWN,EAAKC,GAGzB,OAAOD,CACP,CAED,OAAOM,EAAWN,EAAKC,EACxB"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index a14af41..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 255442ff9e017a81be047939058d3271a55ecc3a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 8 Oct 2023 19:15:46 +0000 Subject: [PATCH 048/119] 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 | 47 +- benchmark/benchmark.js | 290 - benchmark/benchmark.ndims.js | 110 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 68 - docs/types/test.ts | 94 - examples/index.js | 45 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 68 - lib/main.js | 112 - package.json | 64 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 514 -- test/test.js | 514 -- 42 files changed, 6206 insertions(+), 5131 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/benchmark.ndims.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (97%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/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 740d5ce..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/maybe-broadcast-array) 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 4fadc31..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/maybe-broadcast-array) 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 a6e535a..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: '45 9 * * 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 + + ```
@@ -171,7 +164,7 @@ for ( i = 0; i < N; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -231,11 +224,11 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-maybe-broadcast-array/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor +[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor/tree/esm -[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes +[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 9763740..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,290 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var ndarrayBase = require( '@stdlib/ndarray-base-ctor' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArray = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::base_ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::base_ndarray,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( out.shape[ 0 ] !== shape[ 0 ] ) { - b.fail( 'unexpected result' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.ndims.js b/benchmark/benchmark.ndims.js deleted file mode 100644 index b92220c..0000000 --- a/benchmark/benchmark.ndims.js +++ /dev/null @@ -1,110 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var array = require( '@stdlib/ndarray-array' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} ndims - number of dimensions to which to broadcast -* @returns {Function} benchmark function -*/ -function createBenchmark( ndims ) { - var shape; - var sh; - var x; - var i; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - sh = x.shape; - - shape = []; - for ( i = 0; i < ndims; i++ ) { - shape.push( 0 ); - } - for ( i = ndims; i >= 1; i-- ) { - if ( i > sh.length ) { - shape[ ndims-i ] = 5; - } else { - shape[ ndims-i ] = sh[ i-1 ]; - } - } - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( x, shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var min; - var max; - var f; - var i; - - min = 2; - max = 10; - - for ( i = min; i <= max; i++ ) { - f = createBenchmark( i ); - bench( pkg+'::ndarray,2d:from_ndims=2,to_ndims='+i, f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index 90d11e3..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/maybe-broadcast-array" -%% click B href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/maybe-broadcast-array -[production-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 71859ce..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import maybeBroadcastArray from '../docs/types/index'; -export = maybeBroadcastArray; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index a4e6b6b..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var s=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var o=s(function(q,n){ -var a=require('@stdlib/ndarray-base-broadcast-array/dist'),v=require('@stdlib/ndarray-base-shape/dist');function c(e,r){var i,u,t;if(u=r.length,i=v(e),i.length===u){for(t=0;t\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = getShape( arr );\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nmodule.exports = maybeBroadcastArray;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape.\n*\n* @module @stdlib/ndarray-base-maybe-broadcast-array\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var maybeBroadcastArray = require( '@stdlib/ndarray-base-maybe-broadcast-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAY,QAAS,sCAAuC,EAC5DC,EAAW,QAAS,4BAA6B,EA8DrD,SAASC,EAAqBC,EAAKC,EAAQ,CAC1C,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAM,OACVC,EAAKJ,EAAUE,CAAI,EAGdE,EAAG,SAAWC,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,CAAE,IAAMH,EAAOG,CAAE,EAEzB,OAAOP,EAAWG,EAAKC,CAAM,EAG/B,OAAOD,CACR,CAEA,OAAOH,EAAWG,EAAKC,CAAM,CAC9B,CAKAL,EAAO,QAAUG,ICjDjB,IAAIM,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "broadcast", "getShape", "maybeBroadcastArray", "arr", "shape", "sh", "N", "i", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 01ecba8..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,68 +0,0 @@ - -{{alias}}( arr, shape ) - Broadcasts an ndarray to a specified shape if and only if the specified - shape differs from the provided ndarray's shape. - - If a provided ndarray has the same shape as the specified shape, the - function returns the provided ndarray. - - If a provided ndarray has a different (broadcast compatible) shape than the - specified shape, the function returns a new (base) ndarray view of the - provided ndarray's data. The view is typically **not** contiguous. As more - than one element of a returned view may refer to the same memory location, - writing to the view may affect multiple elements. If you need to write to - the returned array, copy the array before performing operations which may - mutate elements. - - A returned array view is a "base" ndarray, and, thus, a returned array view - does not perform bounds checking or afford any of the guarantees of the non- - base ndarray constructor. The primary intent of this function is to - broadcast an ndarray-like object within internal implementations and to do - so with minimal overhead. - - The function throws an error if a provided ndarray is incompatible with a - provided shape. - - Parameters - ---------- - arr: ndarray - Input array. - - shape: ArrayLikeObject - Desired shape. - - Returns - ------- - out: ndarray - Broadcasted array. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > var sh = x.shape - [ 2, 2 ] - > var y = {{alias}}( x, [ 3, 2, 2 ] ) - - > sh = y.shape - [ 3, 2, 2 ] - > var v = y.get( 0, 0, 0 ) - 1 - > v = y.get( 0, 0, 1 ) - 2 - > v = y.get( 0, 1, 0 ) - 3 - > v = y.get( 0, 1, 1 ) - 4 - > v = y.get( 1, 0, 0 ) - 1 - > v = y.get( 1, 1, 0 ) - 3 - > v = y.get( 2, 0, 0 ) - 1 - > v = y.get( 2, 1, 1 ) - 4 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index d7a1a62..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,94 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ndarray } from '@stdlib/types/ndarray'; -import maybeBroadcastArray = require( './index' ); - -/** -* Mock function to create an ndarray-like object. -* -* @return ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns an ndarray... -{ - const x = array(); - - maybeBroadcastArray( x, [ 2, 2, 2 ] ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is not provided a first argument which is an ndarray... -{ - maybeBroadcastArray( '5', [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( 5, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( true, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( false, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( null, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( {}, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( [ '5' ], [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( ( x: number ): number => x, [ 2, 2, 2 ] ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a second argument which is an array-like object containing numbers... -{ - const x = array(); - - maybeBroadcastArray( x, '5' ); // $ExpectError - maybeBroadcastArray( x, 5 ); // $ExpectError - maybeBroadcastArray( x, true ); // $ExpectError - maybeBroadcastArray( x, false ); // $ExpectError - maybeBroadcastArray( x, null ); // $ExpectError - maybeBroadcastArray( x, {} ); // $ExpectError - maybeBroadcastArray( x, [ '5' ] ); // $ExpectError - maybeBroadcastArray( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - - maybeBroadcastArray(); // $ExpectError - maybeBroadcastArray( x ); // $ExpectError - maybeBroadcastArray( x, [ 1, 2, 3 ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index e787d6e..0000000 --- a/examples/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 array = require( '@stdlib/ndarray-array' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var maybeBroadcastArray = require( './../lib' ); - -// Create a 2x2 array: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -// returns - -// Broadcast the array to 3x2x2: -var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -// returns - -// Retrieve the shape: -var sh = y.shape; -// returns [ 3, 2, 2 ] - -// Retrieve the number of elements: -var N = numel( sh ); - -// Loop through the array elements... -var i; -for ( i = 0; i < N; i++ ) { - console.log( 'Y[%s] = %d', ind2sub( sh, i ).join( ', ' ), y.iget( i ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 97% rename from docs/types/index.d.ts rename to index.d.ts index 39826a4..679c9f1 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..c7634b9 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@esm/index.mjs";function e(e,s){var n,a,d;if(a=s.length,(n=t(e)).length===a){for(d=0;d\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = getShape( arr );\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArray;\n"],"names":["maybeBroadcastArray","arr","shape","sh","N","i","length","getShape","broadcast"],"mappings":";;sLAqFA,SAASA,EAAqBC,EAAKC,GAClC,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAMI,QACVH,EAAKI,EAAUN,IAGPK,SAAWF,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,KAAQH,EAAOG,GAEvB,OAAOG,EAAWP,EAAKC,GAGzB,OAAOD,CACP,CAED,OAAOO,EAAWP,EAAKC,EACxB"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 834e930..0000000 --- a/lib/index.js +++ /dev/null @@ -1,68 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* @module @stdlib/ndarray-base-maybe-broadcast-array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var maybeBroadcastArray = require( '@stdlib/ndarray-base-maybe-broadcast-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -*/ - -// 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 73e4742..0000000 --- a/lib/main.js +++ /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. -*/ - -'use strict'; - -// MODULES // - -var broadcast = require( '@stdlib/ndarray-base-broadcast-array' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); - - -// MAIN // - -/** -* Broadcasts an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* ## Notes -* -* - If a provided ndarray has the same shape as the specified shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the specified shape, the function returns a new (base) ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to the view may affect multiple elements. If you need to write to the returned array, copy the array before performing operations which may mutate elements. -* -* @param {ndarray} arr - input array -* @param {NonNegativeIntegerArray} shape - desired shape -* @throws {Error} input array cannot have more dimensions than the desired shape -* @throws {Error} input array dimension sizes must be `1` or equal to the corresponding dimension in the provided shape -* @throws {Error} input array and desired shape must be broadcast compatible -* @returns {ndarray} broadcasted array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var y = maybeBroadcastArray( x, [ 3, 2 ] ); -* // throws -*/ -function maybeBroadcastArray( arr, shape ) { - var sh; - var N; - var i; - - N = shape.length; - sh = getShape( arr ); - - // Check whether we need to broadcast the input array... - if ( sh.length === N ) { - for ( i = 0; i < N; i++ ) { - // Check whether dimensions match... - if ( sh[ i ] !== shape[ i ] ) { - // We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape... - return broadcast( arr, shape ); - } - } - return arr; - } - // If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape... - return broadcast( arr, shape ); -} - - -// EXPORTS // - -module.exports = maybeBroadcastArray; diff --git a/package.json b/package.json index e0fed1c..b74d597 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Broadcast an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's 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", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-base-broadcast-array": "^0.1.0", - "@stdlib/ndarray-base-shape": "github:stdlib-js/ndarray-base-shape#main", - "@stdlib/types": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.1.0", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/bench": "^0.1.0", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-base-ctor": "^0.1.0", - "@stdlib/ndarray-base-numel": "^0.1.1", - "@stdlib/ndarray-ctor": "^0.1.0", - "@stdlib/ndarray-ind2sub": "^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", @@ -86,9 +29,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..c751313 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index 8dadbc7..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,514 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 array = require( '@stdlib/ndarray-array' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var maybeBroadcastArray = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof maybeBroadcastArray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a desired shape which has fewer dimensions than the input array', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 ] - }); - - values = [ - [], - [ 2 ], - [ 2, 2 ], - [ 2, 2, 2 ], - [ 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2, 2, 2 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided a shape with '+values[ i ].length+' dimension' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape having a dimension whose size is less than the corresponding dimension in the input array', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 10, 1 ], - [ 10, 10, 2 ], - [ 10, 10, 9 ], - [ 10, 1, 10 ], - [ 10, 2, 10 ], - [ 10, 9, 10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape and an input array shape which are broadcast-incompatible', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 20, 10 ], - [ 10, 10, 100 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function returns a "base" ndarray instance', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = maybeBroadcastArray( x, [ 2, 2, 2 ] ); - - t.notEqual( y, x, 'returns new instance' ); - t.strictEqual( y instanceof ndarray, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view over the input array data buffer', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = maybeBroadcastArray( x, [ 2, 2, 2 ] ); - - t.strictEqual( y.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; strides)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, -1 ], 3, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; strides)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, 1 ], 2, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; non-contiguous)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ 4, 2 ], 1, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 5 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 7 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (column-major)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'column-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (same shape)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2, 2 ], - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - // Should return the same instance: - t.strictEqual( y, x, 'returns expected value' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 1, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 1, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (same number of dimensions)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1, 2 ], - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (singleton dimension)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (singleton dimension)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 1, 2 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (0-dimensional array)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1 ]; - x = ndarray( 'generic', data, [], [ 0 ], 0, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 7e8e63f..0000000 --- a/test/test.js +++ /dev/null @@ -1,514 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 array = require( '@stdlib/ndarray-array' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var maybeBroadcastArray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof maybeBroadcastArray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a desired shape which has fewer dimensions than the input array', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 ] - }); - - values = [ - [], - [ 2 ], - [ 2, 2 ], - [ 2, 2, 2 ], - [ 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2, 2, 2 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided a shape with '+values[ i ].length+' dimension' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape having a dimension whose size is less than the corresponding dimension in the input array', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 10, 1 ], - [ 10, 10, 2 ], - [ 10, 10, 9 ], - [ 10, 1, 10 ], - [ 10, 2, 10 ], - [ 10, 9, 10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape and an input array shape which are broadcast-incompatible', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 20, 10 ], - [ 10, 10, 100 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function returns a "base" ndarray instance', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = maybeBroadcastArray( x, [ 2, 2, 2 ] ); - - t.notEqual( y, x, 'returns new instance' ); - t.strictEqual( y instanceof ndarray, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view over the input array data buffer', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = maybeBroadcastArray( x, [ 2, 2, 2 ] ); - - t.strictEqual( y.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; strides)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, -1 ], 3, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; strides)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, 1 ], 2, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; non-contiguous)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ 4, 2 ], 1, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 5 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 7 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (column-major)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'column-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (same shape)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2, 2 ], - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - // Should return the same instance: - t.strictEqual( y, x, 'returns expected value' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 1, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 1, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (same number of dimensions)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1, 2 ], - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (singleton dimension)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (singleton dimension)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 1, 2 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (0-dimensional array)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1 ]; - x = ndarray( 'generic', data, [], [ 0 ], 0, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); From e860cd9f897cf54bb464c40f421642b6b11454ad Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 8 Oct 2023 20:25:33 +0000 Subject: [PATCH 049/119] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 15821ed..e0fed1c 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,8 @@ "dependencies": { "@stdlib/ndarray-base-broadcast-array": "^0.1.0", "@stdlib/ndarray-base-shape": "github:stdlib-js/ndarray-base-shape#main", - "@stdlib/types": "^0.1.0" + "@stdlib/types": "^0.1.0", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1" }, "devDependencies": { "@stdlib/array-float64": "^0.1.0", @@ -90,4 +91,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From f79ed0ca88356b0bcbe15ecd424bab78f4f4d4df Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 8 Oct 2023 20:27:50 +0000 Subject: [PATCH 050/119] Remove files --- index.d.ts | 81 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6263 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 679c9f1..0000000 --- a/index.d.ts +++ /dev/null @@ -1,81 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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'; -import { ndarray } from '@stdlib/types/ndarray'; - -/** -* Broadcasts an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* ## Notes -* -* - The function throws an error if a provided ndarray is incompatible with a provided shape. -* - If a provided ndarray has the same shape as the specified shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the specified shape, the function returns a new (base) ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to the view may affect multiple elements. If you need to write to the returned array, copy the array before performing operations which may mutate elements. -* - A returned array view is a "base" ndarray, and, thus, a returned array view does not perform bounds checking or afford any of the guarantees of the non-base ndarray constructor. The primary intent of this function is to broadcast an ndarray-like object within internal implementations and to do so with minimal overhead. -* -* @param arr - input array -* @param shape - desired shape -* @throws input array cannot have more dimensions than the desired shape -* @throws input array dimension sizes must be `1` or equal to the corresponding dimension in the provided shape -* @throws input array and desired shape must be broadcast compatible -* @returns broadcasted array -* -* @example -* var array = require( `@stdlib/ndarray/array` ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -*/ -declare function maybeBroadcastArray( arr: ndarray, shape: ArrayLike ): ndarray; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = maybeBroadcastArray; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index c7634b9..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@esm/index.mjs";function e(e,s){var n,a,d;if(a=s.length,(n=t(e)).length===a){for(d=0;d\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = getShape( arr );\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArray;\n"],"names":["maybeBroadcastArray","arr","shape","sh","N","i","length","getShape","broadcast"],"mappings":";;sLAqFA,SAASA,EAAqBC,EAAKC,GAClC,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAMI,QACVH,EAAKI,EAAUN,IAGPK,SAAWF,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,KAAQH,EAAOG,GAEvB,OAAOG,EAAWP,EAAKC,GAGzB,OAAOD,CACP,CAED,OAAOO,EAAWP,EAAKC,EACxB"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index c751313..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From d35cd7927290b795784e549be7c96dd06bd2c66a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 8 Oct 2023 20:28:52 +0000 Subject: [PATCH 051/119] 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 | 47 +- benchmark/benchmark.js | 290 - benchmark/benchmark.ndims.js | 110 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 68 - docs/types/test.ts | 94 - examples/index.js | 45 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 68 - lib/main.js | 112 - package.json | 64 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 514 -- test/test.js | 514 -- 42 files changed, 6206 insertions(+), 5131 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/benchmark.ndims.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (97%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/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 740d5ce..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/maybe-broadcast-array) 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 4fadc31..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/maybe-broadcast-array) 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 a6e535a..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: '45 9 * * 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 + + ```
@@ -171,7 +164,7 @@ for ( i = 0; i < N; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -231,11 +224,11 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-maybe-broadcast-array/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor +[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor/tree/esm -[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes +[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 9763740..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,290 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var ndarrayBase = require( '@stdlib/ndarray-base-ctor' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArray = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::base_ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::base_ndarray,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( out.shape[ 0 ] !== shape[ 0 ] ) { - b.fail( 'unexpected result' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.ndims.js b/benchmark/benchmark.ndims.js deleted file mode 100644 index b92220c..0000000 --- a/benchmark/benchmark.ndims.js +++ /dev/null @@ -1,110 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var array = require( '@stdlib/ndarray-array' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} ndims - number of dimensions to which to broadcast -* @returns {Function} benchmark function -*/ -function createBenchmark( ndims ) { - var shape; - var sh; - var x; - var i; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - sh = x.shape; - - shape = []; - for ( i = 0; i < ndims; i++ ) { - shape.push( 0 ); - } - for ( i = ndims; i >= 1; i-- ) { - if ( i > sh.length ) { - shape[ ndims-i ] = 5; - } else { - shape[ ndims-i ] = sh[ i-1 ]; - } - } - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( x, shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var min; - var max; - var f; - var i; - - min = 2; - max = 10; - - for ( i = min; i <= max; i++ ) { - f = createBenchmark( i ); - bench( pkg+'::ndarray,2d:from_ndims=2,to_ndims='+i, f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index 90d11e3..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/maybe-broadcast-array" -%% click B href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/maybe-broadcast-array -[production-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 71859ce..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import maybeBroadcastArray from '../docs/types/index'; -export = maybeBroadcastArray; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 4b04e84..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var o=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var s=o(function(l,n){ -var u=require('@stdlib/ndarray-base-broadcast-array/dist'),v=require('@stdlib/ndarray-base-shape/dist');function c(e,r){var i,a,t;if(a=r.length,i=v(e,!1),i.length===a){for(t=0;t\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nmodule.exports = maybeBroadcastArray;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape.\n*\n* @module @stdlib/ndarray-base-maybe-broadcast-array\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var maybeBroadcastArray = require( '@stdlib/ndarray-base-maybe-broadcast-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAY,QAAS,sCAAuC,EAC5DC,EAAW,QAAS,4BAA6B,EA8DrD,SAASC,EAAqBC,EAAKC,EAAQ,CAC1C,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAM,OACVC,EAAKJ,EAAUE,EAAK,EAAM,EAGrBE,EAAG,SAAWC,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,CAAE,IAAMH,EAAOG,CAAE,EAEzB,OAAOP,EAAWG,EAAKC,CAAM,EAG/B,OAAOD,CACR,CAEA,OAAOH,EAAWG,EAAKC,CAAM,CAC9B,CAKAL,EAAO,QAAUG,ICjDjB,IAAIM,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "broadcast", "getShape", "maybeBroadcastArray", "arr", "shape", "sh", "N", "i", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 01ecba8..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,68 +0,0 @@ - -{{alias}}( arr, shape ) - Broadcasts an ndarray to a specified shape if and only if the specified - shape differs from the provided ndarray's shape. - - If a provided ndarray has the same shape as the specified shape, the - function returns the provided ndarray. - - If a provided ndarray has a different (broadcast compatible) shape than the - specified shape, the function returns a new (base) ndarray view of the - provided ndarray's data. The view is typically **not** contiguous. As more - than one element of a returned view may refer to the same memory location, - writing to the view may affect multiple elements. If you need to write to - the returned array, copy the array before performing operations which may - mutate elements. - - A returned array view is a "base" ndarray, and, thus, a returned array view - does not perform bounds checking or afford any of the guarantees of the non- - base ndarray constructor. The primary intent of this function is to - broadcast an ndarray-like object within internal implementations and to do - so with minimal overhead. - - The function throws an error if a provided ndarray is incompatible with a - provided shape. - - Parameters - ---------- - arr: ndarray - Input array. - - shape: ArrayLikeObject - Desired shape. - - Returns - ------- - out: ndarray - Broadcasted array. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > var sh = x.shape - [ 2, 2 ] - > var y = {{alias}}( x, [ 3, 2, 2 ] ) - - > sh = y.shape - [ 3, 2, 2 ] - > var v = y.get( 0, 0, 0 ) - 1 - > v = y.get( 0, 0, 1 ) - 2 - > v = y.get( 0, 1, 0 ) - 3 - > v = y.get( 0, 1, 1 ) - 4 - > v = y.get( 1, 0, 0 ) - 1 - > v = y.get( 1, 1, 0 ) - 3 - > v = y.get( 2, 0, 0 ) - 1 - > v = y.get( 2, 1, 1 ) - 4 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index d7a1a62..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,94 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ndarray } from '@stdlib/types/ndarray'; -import maybeBroadcastArray = require( './index' ); - -/** -* Mock function to create an ndarray-like object. -* -* @return ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns an ndarray... -{ - const x = array(); - - maybeBroadcastArray( x, [ 2, 2, 2 ] ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is not provided a first argument which is an ndarray... -{ - maybeBroadcastArray( '5', [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( 5, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( true, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( false, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( null, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( {}, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( [ '5' ], [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( ( x: number ): number => x, [ 2, 2, 2 ] ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a second argument which is an array-like object containing numbers... -{ - const x = array(); - - maybeBroadcastArray( x, '5' ); // $ExpectError - maybeBroadcastArray( x, 5 ); // $ExpectError - maybeBroadcastArray( x, true ); // $ExpectError - maybeBroadcastArray( x, false ); // $ExpectError - maybeBroadcastArray( x, null ); // $ExpectError - maybeBroadcastArray( x, {} ); // $ExpectError - maybeBroadcastArray( x, [ '5' ] ); // $ExpectError - maybeBroadcastArray( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - - maybeBroadcastArray(); // $ExpectError - maybeBroadcastArray( x ); // $ExpectError - maybeBroadcastArray( x, [ 1, 2, 3 ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index e787d6e..0000000 --- a/examples/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 array = require( '@stdlib/ndarray-array' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var maybeBroadcastArray = require( './../lib' ); - -// Create a 2x2 array: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -// returns - -// Broadcast the array to 3x2x2: -var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -// returns - -// Retrieve the shape: -var sh = y.shape; -// returns [ 3, 2, 2 ] - -// Retrieve the number of elements: -var N = numel( sh ); - -// Loop through the array elements... -var i; -for ( i = 0; i < N; i++ ) { - console.log( 'Y[%s] = %d', ind2sub( sh, i ).join( ', ' ), y.iget( i ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 97% rename from docs/types/index.d.ts rename to index.d.ts index 39826a4..679c9f1 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..96f2a1a --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@esm/index.mjs";function e(e,s){var n,a,d;if(a=s.length,(n=t(e,!1)).length===a){for(d=0;d\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArray;\n"],"names":["maybeBroadcastArray","arr","shape","sh","N","i","length","getShape","broadcast"],"mappings":";;sLAqFA,SAASA,EAAqBC,EAAKC,GAClC,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAMI,QACVH,EAAKI,EAAUN,GAAK,IAGZK,SAAWF,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,KAAQH,EAAOG,GAEvB,OAAOG,EAAWP,EAAKC,GAGzB,OAAOD,CACP,CAED,OAAOO,EAAWP,EAAKC,EACxB"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 834e930..0000000 --- a/lib/index.js +++ /dev/null @@ -1,68 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* @module @stdlib/ndarray-base-maybe-broadcast-array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var maybeBroadcastArray = require( '@stdlib/ndarray-base-maybe-broadcast-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -*/ - -// 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 e59ca1d..0000000 --- a/lib/main.js +++ /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. -*/ - -'use strict'; - -// MODULES // - -var broadcast = require( '@stdlib/ndarray-base-broadcast-array' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); - - -// MAIN // - -/** -* Broadcasts an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* ## Notes -* -* - If a provided ndarray has the same shape as the specified shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the specified shape, the function returns a new (base) ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to the view may affect multiple elements. If you need to write to the returned array, copy the array before performing operations which may mutate elements. -* -* @param {ndarray} arr - input array -* @param {NonNegativeIntegerArray} shape - desired shape -* @throws {Error} input array cannot have more dimensions than the desired shape -* @throws {Error} input array dimension sizes must be `1` or equal to the corresponding dimension in the provided shape -* @throws {Error} input array and desired shape must be broadcast compatible -* @returns {ndarray} broadcasted array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var y = maybeBroadcastArray( x, [ 3, 2 ] ); -* // throws -*/ -function maybeBroadcastArray( arr, shape ) { - var sh; - var N; - var i; - - N = shape.length; - sh = getShape( arr, false ); - - // Check whether we need to broadcast the input array... - if ( sh.length === N ) { - for ( i = 0; i < N; i++ ) { - // Check whether dimensions match... - if ( sh[ i ] !== shape[ i ] ) { - // We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape... - return broadcast( arr, shape ); - } - } - return arr; - } - // If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape... - return broadcast( arr, shape ); -} - - -// EXPORTS // - -module.exports = maybeBroadcastArray; diff --git a/package.json b/package.json index e0fed1c..b74d597 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Broadcast an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's 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", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-base-broadcast-array": "^0.1.0", - "@stdlib/ndarray-base-shape": "github:stdlib-js/ndarray-base-shape#main", - "@stdlib/types": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.1.0", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/bench": "^0.1.0", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-base-ctor": "^0.1.0", - "@stdlib/ndarray-base-numel": "^0.1.1", - "@stdlib/ndarray-ctor": "^0.1.0", - "@stdlib/ndarray-ind2sub": "^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", @@ -86,9 +29,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..15e7ad3 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index 8dadbc7..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,514 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 array = require( '@stdlib/ndarray-array' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var maybeBroadcastArray = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof maybeBroadcastArray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a desired shape which has fewer dimensions than the input array', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 ] - }); - - values = [ - [], - [ 2 ], - [ 2, 2 ], - [ 2, 2, 2 ], - [ 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2, 2, 2 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided a shape with '+values[ i ].length+' dimension' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape having a dimension whose size is less than the corresponding dimension in the input array', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 10, 1 ], - [ 10, 10, 2 ], - [ 10, 10, 9 ], - [ 10, 1, 10 ], - [ 10, 2, 10 ], - [ 10, 9, 10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape and an input array shape which are broadcast-incompatible', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 20, 10 ], - [ 10, 10, 100 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function returns a "base" ndarray instance', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = maybeBroadcastArray( x, [ 2, 2, 2 ] ); - - t.notEqual( y, x, 'returns new instance' ); - t.strictEqual( y instanceof ndarray, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view over the input array data buffer', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = maybeBroadcastArray( x, [ 2, 2, 2 ] ); - - t.strictEqual( y.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; strides)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, -1 ], 3, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; strides)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, 1 ], 2, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; non-contiguous)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ 4, 2 ], 1, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 5 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 7 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (column-major)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'column-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (same shape)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2, 2 ], - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - // Should return the same instance: - t.strictEqual( y, x, 'returns expected value' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 1, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 1, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (same number of dimensions)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1, 2 ], - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (singleton dimension)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (singleton dimension)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 1, 2 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (0-dimensional array)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1 ]; - x = ndarray( 'generic', data, [], [ 0 ], 0, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 7e8e63f..0000000 --- a/test/test.js +++ /dev/null @@ -1,514 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 array = require( '@stdlib/ndarray-array' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var maybeBroadcastArray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof maybeBroadcastArray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a desired shape which has fewer dimensions than the input array', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 ] - }); - - values = [ - [], - [ 2 ], - [ 2, 2 ], - [ 2, 2, 2 ], - [ 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2, 2, 2 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided a shape with '+values[ i ].length+' dimension' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape having a dimension whose size is less than the corresponding dimension in the input array', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 10, 1 ], - [ 10, 10, 2 ], - [ 10, 10, 9 ], - [ 10, 1, 10 ], - [ 10, 2, 10 ], - [ 10, 9, 10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape and an input array shape which are broadcast-incompatible', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 20, 10 ], - [ 10, 10, 100 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function returns a "base" ndarray instance', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = maybeBroadcastArray( x, [ 2, 2, 2 ] ); - - t.notEqual( y, x, 'returns new instance' ); - t.strictEqual( y instanceof ndarray, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view over the input array data buffer', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = maybeBroadcastArray( x, [ 2, 2, 2 ] ); - - t.strictEqual( y.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; strides)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, -1 ], 3, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; strides)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, 1 ], 2, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; non-contiguous)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ 4, 2 ], 1, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 5 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 7 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (column-major)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'column-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (same shape)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2, 2 ], - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - // Should return the same instance: - t.strictEqual( y, x, 'returns expected value' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 1, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 1, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (same number of dimensions)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1, 2 ], - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (singleton dimension)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (singleton dimension)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 1, 2 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (0-dimensional array)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1 ]; - x = ndarray( 'generic', data, [], [ 0 ], 0, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); From 4f2b0004b761a07774f47a2d2f9834e4e739a796 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Nov 2023 17:06:10 +0000 Subject: [PATCH 052/119] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 6eab36f..0bf6e1c 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,8 @@ "dependencies": { "@stdlib/ndarray-base-broadcast-array": "^0.1.0", "@stdlib/ndarray-base-shape": "^0.1.0", - "@stdlib/types": "^0.1.0" + "@stdlib/types": "^0.1.0", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1" }, "devDependencies": { "@stdlib/array-float64": "^0.1.1", @@ -90,4 +91,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From cedad5f9f235665555861138ee67c3638bbfafc3 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 3 Nov 2023 01:35:42 +0000 Subject: [PATCH 053/119] Remove files --- index.d.ts | 81 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6263 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 679c9f1..0000000 --- a/index.d.ts +++ /dev/null @@ -1,81 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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'; -import { ndarray } from '@stdlib/types/ndarray'; - -/** -* Broadcasts an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* ## Notes -* -* - The function throws an error if a provided ndarray is incompatible with a provided shape. -* - If a provided ndarray has the same shape as the specified shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the specified shape, the function returns a new (base) ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to the view may affect multiple elements. If you need to write to the returned array, copy the array before performing operations which may mutate elements. -* - A returned array view is a "base" ndarray, and, thus, a returned array view does not perform bounds checking or afford any of the guarantees of the non-base ndarray constructor. The primary intent of this function is to broadcast an ndarray-like object within internal implementations and to do so with minimal overhead. -* -* @param arr - input array -* @param shape - desired shape -* @throws input array cannot have more dimensions than the desired shape -* @throws input array dimension sizes must be `1` or equal to the corresponding dimension in the provided shape -* @throws input array and desired shape must be broadcast compatible -* @returns broadcasted array -* -* @example -* var array = require( `@stdlib/ndarray/array` ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -*/ -declare function maybeBroadcastArray( arr: ndarray, shape: ArrayLike ): ndarray; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = maybeBroadcastArray; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 96f2a1a..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@esm/index.mjs";function e(e,s){var n,a,d;if(a=s.length,(n=t(e,!1)).length===a){for(d=0;d\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArray;\n"],"names":["maybeBroadcastArray","arr","shape","sh","N","i","length","getShape","broadcast"],"mappings":";;sLAqFA,SAASA,EAAqBC,EAAKC,GAClC,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAMI,QACVH,EAAKI,EAAUN,GAAK,IAGZK,SAAWF,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,KAAQH,EAAOG,GAEvB,OAAOG,EAAWP,EAAKC,GAGzB,OAAOD,CACP,CAED,OAAOO,EAAWP,EAAKC,EACxB"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 15e7ad3..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From de8062033458c113213a12c497db6d63f07fda85 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 3 Nov 2023 01:36:39 +0000 Subject: [PATCH 054/119] 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 | 47 +- benchmark/benchmark.js | 290 - benchmark/benchmark.ndims.js | 110 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 68 - docs/types/test.ts | 94 - examples/index.js | 45 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 68 - lib/main.js | 112 - package.json | 64 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 514 -- 43 files changed, 6206 insertions(+), 4659 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/benchmark.ndims.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (97%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/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 71e3386..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-11-01T05:31:38.456Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 740d5ce..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/maybe-broadcast-array) 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 4fadc31..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/maybe-broadcast-array) 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 a6e535a..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: '45 9 * * 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 + + ```
@@ -171,7 +164,7 @@ for ( i = 0; i < N; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -231,11 +224,11 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-maybe-broadcast-array/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor +[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor/tree/esm -[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes +[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 9763740..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,290 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var ndarrayBase = require( '@stdlib/ndarray-base-ctor' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArray = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::base_ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::base_ndarray,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( out.shape[ 0 ] !== shape[ 0 ] ) { - b.fail( 'unexpected result' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.ndims.js b/benchmark/benchmark.ndims.js deleted file mode 100644 index b92220c..0000000 --- a/benchmark/benchmark.ndims.js +++ /dev/null @@ -1,110 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var array = require( '@stdlib/ndarray-array' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} ndims - number of dimensions to which to broadcast -* @returns {Function} benchmark function -*/ -function createBenchmark( ndims ) { - var shape; - var sh; - var x; - var i; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - sh = x.shape; - - shape = []; - for ( i = 0; i < ndims; i++ ) { - shape.push( 0 ); - } - for ( i = ndims; i >= 1; i-- ) { - if ( i > sh.length ) { - shape[ ndims-i ] = 5; - } else { - shape[ ndims-i ] = sh[ i-1 ]; - } - } - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( x, shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var min; - var max; - var f; - var i; - - min = 2; - max = 10; - - for ( i = min; i <= max; i++ ) { - f = createBenchmark( i ); - bench( pkg+'::ndarray,2d:from_ndims=2,to_ndims='+i, f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index 90d11e3..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/maybe-broadcast-array" -%% click B href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/maybe-broadcast-array -[production-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 71859ce..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import maybeBroadcastArray from '../docs/types/index'; -export = maybeBroadcastArray; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 4b04e84..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var o=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var s=o(function(l,n){ -var u=require('@stdlib/ndarray-base-broadcast-array/dist'),v=require('@stdlib/ndarray-base-shape/dist');function c(e,r){var i,a,t;if(a=r.length,i=v(e,!1),i.length===a){for(t=0;t\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nmodule.exports = maybeBroadcastArray;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape.\n*\n* @module @stdlib/ndarray-base-maybe-broadcast-array\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var maybeBroadcastArray = require( '@stdlib/ndarray-base-maybe-broadcast-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAY,QAAS,sCAAuC,EAC5DC,EAAW,QAAS,4BAA6B,EA8DrD,SAASC,EAAqBC,EAAKC,EAAQ,CAC1C,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAM,OACVC,EAAKJ,EAAUE,EAAK,EAAM,EAGrBE,EAAG,SAAWC,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,CAAE,IAAMH,EAAOG,CAAE,EAEzB,OAAOP,EAAWG,EAAKC,CAAM,EAG/B,OAAOD,CACR,CAEA,OAAOH,EAAWG,EAAKC,CAAM,CAC9B,CAKAL,EAAO,QAAUG,ICjDjB,IAAIM,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "broadcast", "getShape", "maybeBroadcastArray", "arr", "shape", "sh", "N", "i", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 01ecba8..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,68 +0,0 @@ - -{{alias}}( arr, shape ) - Broadcasts an ndarray to a specified shape if and only if the specified - shape differs from the provided ndarray's shape. - - If a provided ndarray has the same shape as the specified shape, the - function returns the provided ndarray. - - If a provided ndarray has a different (broadcast compatible) shape than the - specified shape, the function returns a new (base) ndarray view of the - provided ndarray's data. The view is typically **not** contiguous. As more - than one element of a returned view may refer to the same memory location, - writing to the view may affect multiple elements. If you need to write to - the returned array, copy the array before performing operations which may - mutate elements. - - A returned array view is a "base" ndarray, and, thus, a returned array view - does not perform bounds checking or afford any of the guarantees of the non- - base ndarray constructor. The primary intent of this function is to - broadcast an ndarray-like object within internal implementations and to do - so with minimal overhead. - - The function throws an error if a provided ndarray is incompatible with a - provided shape. - - Parameters - ---------- - arr: ndarray - Input array. - - shape: ArrayLikeObject - Desired shape. - - Returns - ------- - out: ndarray - Broadcasted array. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > var sh = x.shape - [ 2, 2 ] - > var y = {{alias}}( x, [ 3, 2, 2 ] ) - - > sh = y.shape - [ 3, 2, 2 ] - > var v = y.get( 0, 0, 0 ) - 1 - > v = y.get( 0, 0, 1 ) - 2 - > v = y.get( 0, 1, 0 ) - 3 - > v = y.get( 0, 1, 1 ) - 4 - > v = y.get( 1, 0, 0 ) - 1 - > v = y.get( 1, 1, 0 ) - 3 - > v = y.get( 2, 0, 0 ) - 1 - > v = y.get( 2, 1, 1 ) - 4 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index d7a1a62..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,94 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ndarray } from '@stdlib/types/ndarray'; -import maybeBroadcastArray = require( './index' ); - -/** -* Mock function to create an ndarray-like object. -* -* @return ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns an ndarray... -{ - const x = array(); - - maybeBroadcastArray( x, [ 2, 2, 2 ] ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is not provided a first argument which is an ndarray... -{ - maybeBroadcastArray( '5', [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( 5, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( true, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( false, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( null, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( {}, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( [ '5' ], [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( ( x: number ): number => x, [ 2, 2, 2 ] ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a second argument which is an array-like object containing numbers... -{ - const x = array(); - - maybeBroadcastArray( x, '5' ); // $ExpectError - maybeBroadcastArray( x, 5 ); // $ExpectError - maybeBroadcastArray( x, true ); // $ExpectError - maybeBroadcastArray( x, false ); // $ExpectError - maybeBroadcastArray( x, null ); // $ExpectError - maybeBroadcastArray( x, {} ); // $ExpectError - maybeBroadcastArray( x, [ '5' ] ); // $ExpectError - maybeBroadcastArray( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - - maybeBroadcastArray(); // $ExpectError - maybeBroadcastArray( x ); // $ExpectError - maybeBroadcastArray( x, [ 1, 2, 3 ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index e787d6e..0000000 --- a/examples/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 array = require( '@stdlib/ndarray-array' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var maybeBroadcastArray = require( './../lib' ); - -// Create a 2x2 array: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -// returns - -// Broadcast the array to 3x2x2: -var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -// returns - -// Retrieve the shape: -var sh = y.shape; -// returns [ 3, 2, 2 ] - -// Retrieve the number of elements: -var N = numel( sh ); - -// Loop through the array elements... -var i; -for ( i = 0; i < N; i++ ) { - console.log( 'Y[%s] = %d', ind2sub( sh, i ).join( ', ' ), y.iget( i ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 97% rename from docs/types/index.d.ts rename to index.d.ts index 39826a4..679c9f1 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..321ff74 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.1.0-esm/index.mjs";function e(e,s){var n,a,d;if(a=s.length,(n=t(e,!1)).length===a){for(d=0;d\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArray;\n"],"names":["maybeBroadcastArray","arr","shape","sh","N","i","length","getShape","broadcast"],"mappings":";;6LAqFA,SAASA,EAAqBC,EAAKC,GAClC,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAMI,QACVH,EAAKI,EAAUN,GAAK,IAGZK,SAAWF,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,KAAQH,EAAOG,GAEvB,OAAOG,EAAWP,EAAKC,GAGzB,OAAOD,CACP,CAED,OAAOO,EAAWP,EAAKC,EACxB"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 834e930..0000000 --- a/lib/index.js +++ /dev/null @@ -1,68 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* @module @stdlib/ndarray-base-maybe-broadcast-array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var maybeBroadcastArray = require( '@stdlib/ndarray-base-maybe-broadcast-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -*/ - -// 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 e59ca1d..0000000 --- a/lib/main.js +++ /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. -*/ - -'use strict'; - -// MODULES // - -var broadcast = require( '@stdlib/ndarray-base-broadcast-array' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); - - -// MAIN // - -/** -* Broadcasts an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* ## Notes -* -* - If a provided ndarray has the same shape as the specified shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the specified shape, the function returns a new (base) ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to the view may affect multiple elements. If you need to write to the returned array, copy the array before performing operations which may mutate elements. -* -* @param {ndarray} arr - input array -* @param {NonNegativeIntegerArray} shape - desired shape -* @throws {Error} input array cannot have more dimensions than the desired shape -* @throws {Error} input array dimension sizes must be `1` or equal to the corresponding dimension in the provided shape -* @throws {Error} input array and desired shape must be broadcast compatible -* @returns {ndarray} broadcasted array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var y = maybeBroadcastArray( x, [ 3, 2 ] ); -* // throws -*/ -function maybeBroadcastArray( arr, shape ) { - var sh; - var N; - var i; - - N = shape.length; - sh = getShape( arr, false ); - - // Check whether we need to broadcast the input array... - if ( sh.length === N ) { - for ( i = 0; i < N; i++ ) { - // Check whether dimensions match... - if ( sh[ i ] !== shape[ i ] ) { - // We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape... - return broadcast( arr, shape ); - } - } - return arr; - } - // If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape... - return broadcast( arr, shape ); -} - - -// EXPORTS // - -module.exports = maybeBroadcastArray; diff --git a/package.json b/package.json index 0bf6e1c..b74d597 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Broadcast an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's 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", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-base-broadcast-array": "^0.1.0", - "@stdlib/ndarray-base-shape": "^0.1.0", - "@stdlib/types": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.1.1", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/bench": "^0.1.0", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-base-ctor": "^0.1.0", - "@stdlib/ndarray-base-numel": "^0.1.1", - "@stdlib/ndarray-ctor": "^0.1.0", - "@stdlib/ndarray-ind2sub": "^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", @@ -86,9 +29,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..4af51ad --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 7e8e63f..0000000 --- a/test/test.js +++ /dev/null @@ -1,514 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 array = require( '@stdlib/ndarray-array' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var maybeBroadcastArray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof maybeBroadcastArray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a desired shape which has fewer dimensions than the input array', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 ] - }); - - values = [ - [], - [ 2 ], - [ 2, 2 ], - [ 2, 2, 2 ], - [ 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2, 2, 2 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided a shape with '+values[ i ].length+' dimension' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape having a dimension whose size is less than the corresponding dimension in the input array', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 10, 1 ], - [ 10, 10, 2 ], - [ 10, 10, 9 ], - [ 10, 1, 10 ], - [ 10, 2, 10 ], - [ 10, 9, 10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape and an input array shape which are broadcast-incompatible', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 20, 10 ], - [ 10, 10, 100 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function returns a "base" ndarray instance', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = maybeBroadcastArray( x, [ 2, 2, 2 ] ); - - t.notEqual( y, x, 'returns new instance' ); - t.strictEqual( y instanceof ndarray, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view over the input array data buffer', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = maybeBroadcastArray( x, [ 2, 2, 2 ] ); - - t.strictEqual( y.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; strides)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, -1 ], 3, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; strides)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, 1 ], 2, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; non-contiguous)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ 4, 2 ], 1, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 5 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 7 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (column-major)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'column-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (same shape)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2, 2 ], - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - // Should return the same instance: - t.strictEqual( y, x, 'returns expected value' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 1, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 1, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (same number of dimensions)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1, 2 ], - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (singleton dimension)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (singleton dimension)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 1, 2 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (0-dimensional array)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1 ]; - x = ndarray( 'generic', data, [], [ 0 ], 0, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); From ccacdbb090a3c7bc0c34e9089d3b0aec34cfca24 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Dec 2023 13:16:58 +0000 Subject: [PATCH 055/119] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 245aaa4..13ffa1a 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,8 @@ "dependencies": { "@stdlib/ndarray-base-broadcast-array": "^0.1.0", "@stdlib/ndarray-base-shape": "^0.1.0", - "@stdlib/types": "^0.2.0" + "@stdlib/types": "^0.2.0", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1" }, "devDependencies": { "@stdlib/array-float64": "^0.1.1", @@ -90,4 +91,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From 07b254648f4fb19fe7b69510e8f56be924920655 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 2 Dec 2023 11:12:41 +0000 Subject: [PATCH 056/119] Remove files --- index.d.ts | 81 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6263 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 679c9f1..0000000 --- a/index.d.ts +++ /dev/null @@ -1,81 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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'; -import { ndarray } from '@stdlib/types/ndarray'; - -/** -* Broadcasts an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* ## Notes -* -* - The function throws an error if a provided ndarray is incompatible with a provided shape. -* - If a provided ndarray has the same shape as the specified shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the specified shape, the function returns a new (base) ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to the view may affect multiple elements. If you need to write to the returned array, copy the array before performing operations which may mutate elements. -* - A returned array view is a "base" ndarray, and, thus, a returned array view does not perform bounds checking or afford any of the guarantees of the non-base ndarray constructor. The primary intent of this function is to broadcast an ndarray-like object within internal implementations and to do so with minimal overhead. -* -* @param arr - input array -* @param shape - desired shape -* @throws input array cannot have more dimensions than the desired shape -* @throws input array dimension sizes must be `1` or equal to the corresponding dimension in the provided shape -* @throws input array and desired shape must be broadcast compatible -* @returns broadcasted array -* -* @example -* var array = require( `@stdlib/ndarray/array` ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -*/ -declare function maybeBroadcastArray( arr: ndarray, shape: ArrayLike ): ndarray; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = maybeBroadcastArray; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 321ff74..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.1.0-esm/index.mjs";function e(e,s){var n,a,d;if(a=s.length,(n=t(e,!1)).length===a){for(d=0;d\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArray;\n"],"names":["maybeBroadcastArray","arr","shape","sh","N","i","length","getShape","broadcast"],"mappings":";;6LAqFA,SAASA,EAAqBC,EAAKC,GAClC,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAMI,QACVH,EAAKI,EAAUN,GAAK,IAGZK,SAAWF,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,KAAQH,EAAOG,GAEvB,OAAOG,EAAWP,EAAKC,GAGzB,OAAOD,CACP,CAED,OAAOO,EAAWP,EAAKC,EACxB"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 4af51ad..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 75439433a5cd3727f4fafc4c696d718c8d936f89 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 2 Dec 2023 11:13:27 +0000 Subject: [PATCH 057/119] 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 | 47 +- benchmark/benchmark.js | 290 - benchmark/benchmark.ndims.js | 110 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 68 - docs/types/test.ts | 94 - examples/index.js | 45 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 68 - lib/main.js | 112 - package.json | 64 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 514 -- 43 files changed, 6206 insertions(+), 4654 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/benchmark.ndims.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (97%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/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 725ad45..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-12-01T05:36:17.733Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 740d5ce..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/maybe-broadcast-array) 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 4fadc31..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/maybe-broadcast-array) 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 a6e535a..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: '45 9 * * 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 + + ```
@@ -171,7 +164,7 @@ for ( i = 0; i < N; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -231,11 +224,11 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-maybe-broadcast-array/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor +[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor/tree/esm -[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes +[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 9763740..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,290 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var ndarrayBase = require( '@stdlib/ndarray-base-ctor' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArray = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::base_ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::base_ndarray,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( out.shape[ 0 ] !== shape[ 0 ] ) { - b.fail( 'unexpected result' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.ndims.js b/benchmark/benchmark.ndims.js deleted file mode 100644 index b92220c..0000000 --- a/benchmark/benchmark.ndims.js +++ /dev/null @@ -1,110 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var array = require( '@stdlib/ndarray-array' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} ndims - number of dimensions to which to broadcast -* @returns {Function} benchmark function -*/ -function createBenchmark( ndims ) { - var shape; - var sh; - var x; - var i; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - sh = x.shape; - - shape = []; - for ( i = 0; i < ndims; i++ ) { - shape.push( 0 ); - } - for ( i = ndims; i >= 1; i-- ) { - if ( i > sh.length ) { - shape[ ndims-i ] = 5; - } else { - shape[ ndims-i ] = sh[ i-1 ]; - } - } - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( x, shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var min; - var max; - var f; - var i; - - min = 2; - max = 10; - - for ( i = min; i <= max; i++ ) { - f = createBenchmark( i ); - bench( pkg+'::ndarray,2d:from_ndims=2,to_ndims='+i, f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index 90d11e3..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/maybe-broadcast-array" -%% click B href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/maybe-broadcast-array -[production-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 71859ce..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import maybeBroadcastArray from '../docs/types/index'; -export = maybeBroadcastArray; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 4b04e84..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var o=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var s=o(function(l,n){ -var u=require('@stdlib/ndarray-base-broadcast-array/dist'),v=require('@stdlib/ndarray-base-shape/dist');function c(e,r){var i,a,t;if(a=r.length,i=v(e,!1),i.length===a){for(t=0;t\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nmodule.exports = maybeBroadcastArray;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape.\n*\n* @module @stdlib/ndarray-base-maybe-broadcast-array\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var maybeBroadcastArray = require( '@stdlib/ndarray-base-maybe-broadcast-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAY,QAAS,sCAAuC,EAC5DC,EAAW,QAAS,4BAA6B,EA8DrD,SAASC,EAAqBC,EAAKC,EAAQ,CAC1C,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAM,OACVC,EAAKJ,EAAUE,EAAK,EAAM,EAGrBE,EAAG,SAAWC,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,CAAE,IAAMH,EAAOG,CAAE,EAEzB,OAAOP,EAAWG,EAAKC,CAAM,EAG/B,OAAOD,CACR,CAEA,OAAOH,EAAWG,EAAKC,CAAM,CAC9B,CAKAL,EAAO,QAAUG,ICjDjB,IAAIM,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "broadcast", "getShape", "maybeBroadcastArray", "arr", "shape", "sh", "N", "i", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 01ecba8..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,68 +0,0 @@ - -{{alias}}( arr, shape ) - Broadcasts an ndarray to a specified shape if and only if the specified - shape differs from the provided ndarray's shape. - - If a provided ndarray has the same shape as the specified shape, the - function returns the provided ndarray. - - If a provided ndarray has a different (broadcast compatible) shape than the - specified shape, the function returns a new (base) ndarray view of the - provided ndarray's data. The view is typically **not** contiguous. As more - than one element of a returned view may refer to the same memory location, - writing to the view may affect multiple elements. If you need to write to - the returned array, copy the array before performing operations which may - mutate elements. - - A returned array view is a "base" ndarray, and, thus, a returned array view - does not perform bounds checking or afford any of the guarantees of the non- - base ndarray constructor. The primary intent of this function is to - broadcast an ndarray-like object within internal implementations and to do - so with minimal overhead. - - The function throws an error if a provided ndarray is incompatible with a - provided shape. - - Parameters - ---------- - arr: ndarray - Input array. - - shape: ArrayLikeObject - Desired shape. - - Returns - ------- - out: ndarray - Broadcasted array. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > var sh = x.shape - [ 2, 2 ] - > var y = {{alias}}( x, [ 3, 2, 2 ] ) - - > sh = y.shape - [ 3, 2, 2 ] - > var v = y.get( 0, 0, 0 ) - 1 - > v = y.get( 0, 0, 1 ) - 2 - > v = y.get( 0, 1, 0 ) - 3 - > v = y.get( 0, 1, 1 ) - 4 - > v = y.get( 1, 0, 0 ) - 1 - > v = y.get( 1, 1, 0 ) - 3 - > v = y.get( 2, 0, 0 ) - 1 - > v = y.get( 2, 1, 1 ) - 4 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index d7a1a62..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,94 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ndarray } from '@stdlib/types/ndarray'; -import maybeBroadcastArray = require( './index' ); - -/** -* Mock function to create an ndarray-like object. -* -* @return ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns an ndarray... -{ - const x = array(); - - maybeBroadcastArray( x, [ 2, 2, 2 ] ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is not provided a first argument which is an ndarray... -{ - maybeBroadcastArray( '5', [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( 5, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( true, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( false, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( null, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( {}, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( [ '5' ], [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( ( x: number ): number => x, [ 2, 2, 2 ] ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a second argument which is an array-like object containing numbers... -{ - const x = array(); - - maybeBroadcastArray( x, '5' ); // $ExpectError - maybeBroadcastArray( x, 5 ); // $ExpectError - maybeBroadcastArray( x, true ); // $ExpectError - maybeBroadcastArray( x, false ); // $ExpectError - maybeBroadcastArray( x, null ); // $ExpectError - maybeBroadcastArray( x, {} ); // $ExpectError - maybeBroadcastArray( x, [ '5' ] ); // $ExpectError - maybeBroadcastArray( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - - maybeBroadcastArray(); // $ExpectError - maybeBroadcastArray( x ); // $ExpectError - maybeBroadcastArray( x, [ 1, 2, 3 ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index e787d6e..0000000 --- a/examples/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 array = require( '@stdlib/ndarray-array' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var maybeBroadcastArray = require( './../lib' ); - -// Create a 2x2 array: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -// returns - -// Broadcast the array to 3x2x2: -var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -// returns - -// Retrieve the shape: -var sh = y.shape; -// returns [ 3, 2, 2 ] - -// Retrieve the number of elements: -var N = numel( sh ); - -// Loop through the array elements... -var i; -for ( i = 0; i < N; i++ ) { - console.log( 'Y[%s] = %d', ind2sub( sh, i ).join( ', ' ), y.iget( i ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 97% rename from docs/types/index.d.ts rename to index.d.ts index c5bf290..69168e4 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..321ff74 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.1.0-esm/index.mjs";function e(e,s){var n,a,d;if(a=s.length,(n=t(e,!1)).length===a){for(d=0;d\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArray;\n"],"names":["maybeBroadcastArray","arr","shape","sh","N","i","length","getShape","broadcast"],"mappings":";;6LAqFA,SAASA,EAAqBC,EAAKC,GAClC,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAMI,QACVH,EAAKI,EAAUN,GAAK,IAGZK,SAAWF,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,KAAQH,EAAOG,GAEvB,OAAOG,EAAWP,EAAKC,GAGzB,OAAOD,CACP,CAED,OAAOO,EAAWP,EAAKC,EACxB"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 834e930..0000000 --- a/lib/index.js +++ /dev/null @@ -1,68 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* @module @stdlib/ndarray-base-maybe-broadcast-array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var maybeBroadcastArray = require( '@stdlib/ndarray-base-maybe-broadcast-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -*/ - -// 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 e59ca1d..0000000 --- a/lib/main.js +++ /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. -*/ - -'use strict'; - -// MODULES // - -var broadcast = require( '@stdlib/ndarray-base-broadcast-array' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); - - -// MAIN // - -/** -* Broadcasts an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* ## Notes -* -* - If a provided ndarray has the same shape as the specified shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the specified shape, the function returns a new (base) ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to the view may affect multiple elements. If you need to write to the returned array, copy the array before performing operations which may mutate elements. -* -* @param {ndarray} arr - input array -* @param {NonNegativeIntegerArray} shape - desired shape -* @throws {Error} input array cannot have more dimensions than the desired shape -* @throws {Error} input array dimension sizes must be `1` or equal to the corresponding dimension in the provided shape -* @throws {Error} input array and desired shape must be broadcast compatible -* @returns {ndarray} broadcasted array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var y = maybeBroadcastArray( x, [ 3, 2 ] ); -* // throws -*/ -function maybeBroadcastArray( arr, shape ) { - var sh; - var N; - var i; - - N = shape.length; - sh = getShape( arr, false ); - - // Check whether we need to broadcast the input array... - if ( sh.length === N ) { - for ( i = 0; i < N; i++ ) { - // Check whether dimensions match... - if ( sh[ i ] !== shape[ i ] ) { - // We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape... - return broadcast( arr, shape ); - } - } - return arr; - } - // If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape... - return broadcast( arr, shape ); -} - - -// EXPORTS // - -module.exports = maybeBroadcastArray; diff --git a/package.json b/package.json index 13ffa1a..b74d597 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Broadcast an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's 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", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-base-broadcast-array": "^0.1.0", - "@stdlib/ndarray-base-shape": "^0.1.0", - "@stdlib/types": "^0.2.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.1.1", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/bench": "^0.2.1", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-base-ctor": "^0.1.0", - "@stdlib/ndarray-base-numel": "^0.1.1", - "@stdlib/ndarray-ctor": "^0.1.0", - "@stdlib/ndarray-ind2sub": "^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", @@ -86,9 +29,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..c381ee9 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 7e8e63f..0000000 --- a/test/test.js +++ /dev/null @@ -1,514 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 array = require( '@stdlib/ndarray-array' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var maybeBroadcastArray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof maybeBroadcastArray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a desired shape which has fewer dimensions than the input array', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 ] - }); - - values = [ - [], - [ 2 ], - [ 2, 2 ], - [ 2, 2, 2 ], - [ 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2, 2, 2 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided a shape with '+values[ i ].length+' dimension' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape having a dimension whose size is less than the corresponding dimension in the input array', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 10, 1 ], - [ 10, 10, 2 ], - [ 10, 10, 9 ], - [ 10, 1, 10 ], - [ 10, 2, 10 ], - [ 10, 9, 10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape and an input array shape which are broadcast-incompatible', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 20, 10 ], - [ 10, 10, 100 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function returns a "base" ndarray instance', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = maybeBroadcastArray( x, [ 2, 2, 2 ] ); - - t.notEqual( y, x, 'returns new instance' ); - t.strictEqual( y instanceof ndarray, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view over the input array data buffer', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = maybeBroadcastArray( x, [ 2, 2, 2 ] ); - - t.strictEqual( y.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; strides)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, -1 ], 3, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; strides)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, 1 ], 2, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; non-contiguous)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ 4, 2 ], 1, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 5 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 7 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (column-major)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'column-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (same shape)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2, 2 ], - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - // Should return the same instance: - t.strictEqual( y, x, 'returns expected value' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 1, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 1, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (same number of dimensions)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1, 2 ], - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (singleton dimension)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (singleton dimension)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 1, 2 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (0-dimensional array)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1 ]; - x = ndarray( 'generic', data, [], [ 0 ], 0, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); From ddf1c58109b126d7a6000d6fe4da8470ad12925b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 07:55:32 +0000 Subject: [PATCH 058/119] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 9777183..b4246f2 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,8 @@ "dependencies": { "@stdlib/ndarray-base-broadcast-array": "^0.1.0", "@stdlib/ndarray-base-shape": "^0.1.0", - "@stdlib/types": "^0.2.0" + "@stdlib/types": "^0.2.0", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1" }, "devDependencies": { "@stdlib/array-float64": "^0.1.1", @@ -90,4 +91,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From d57c37202250eb368f1dd1bd5ee97eea6a4f0223 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 14:34:08 +0000 Subject: [PATCH 059/119] Remove files --- index.d.ts | 81 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6263 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 69168e4..0000000 --- a/index.d.ts +++ /dev/null @@ -1,81 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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'; -import { ndarray } from '@stdlib/types/ndarray'; - -/** -* Broadcasts an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* ## Notes -* -* - The function throws an error if a provided ndarray is incompatible with a provided shape. -* - If a provided ndarray has the same shape as the specified shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the specified shape, the function returns a new (base) ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to the view may affect multiple elements. If you need to write to the returned array, copy the array before performing operations which may mutate elements. -* - A returned array view is a "base" ndarray, and, thus, a returned array view does not perform bounds checking or afford any of the guarantees of the non-base ndarray constructor. The primary intent of this function is to broadcast an ndarray-like object within internal implementations and to do so with minimal overhead. -* -* @param arr - input array -* @param shape - desired shape -* @throws input array cannot have more dimensions than the desired shape -* @throws input array dimension sizes must be `1` or equal to the corresponding dimension in the provided shape -* @throws input array and desired shape must be broadcast compatible -* @returns broadcasted array -* -* @example -* var array = require( `@stdlib/ndarray/array` ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -*/ -declare function maybeBroadcastArray( arr: ndarray, shape: ArrayLike ): ndarray; - - -// EXPORTS // - -export = maybeBroadcastArray; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 321ff74..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.1.0-esm/index.mjs";function e(e,s){var n,a,d;if(a=s.length,(n=t(e,!1)).length===a){for(d=0;d\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArray;\n"],"names":["maybeBroadcastArray","arr","shape","sh","N","i","length","getShape","broadcast"],"mappings":";;6LAqFA,SAASA,EAAqBC,EAAKC,GAClC,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAMI,QACVH,EAAKI,EAAUN,GAAK,IAGZK,SAAWF,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,KAAQH,EAAOG,GAEvB,OAAOG,EAAWP,EAAKC,GAGzB,OAAOD,CACP,CAED,OAAOO,EAAWP,EAAKC,EACxB"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index c381ee9..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 8b5cb4724fc64e9ddd5fa33cc70d2698b1114033 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 14:34:38 +0000 Subject: [PATCH 060/119] 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 | 47 +- SECURITY.md | 5 - benchmark/benchmark.js | 290 - benchmark/benchmark.ndims.js | 110 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 68 - docs/types/test.ts | 94 - examples/index.js | 45 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 68 - lib/main.js | 112 - package.json | 64 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 514 -- 44 files changed, 6206 insertions(+), 4660 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/benchmark.ndims.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (97%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/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 f0ca274..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-01-01T05:05:45.743Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 740d5ce..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/maybe-broadcast-array) 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 4fadc31..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/maybe-broadcast-array) 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 e33a55c..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: '45 9 * * 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 + + ```
@@ -171,7 +164,7 @@ for ( i = 0; i < N; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -231,11 +224,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-maybe-broadcast-array/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor +[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor/tree/esm -[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes +[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm
diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index ba5f734..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,290 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var ndarrayBase = require( '@stdlib/ndarray-base-ctor' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArray = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::base_ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::base_ndarray,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( out.shape[ 0 ] !== shape[ 0 ] ) { - b.fail( 'unexpected result' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.ndims.js b/benchmark/benchmark.ndims.js deleted file mode 100644 index 739b74c..0000000 --- a/benchmark/benchmark.ndims.js +++ /dev/null @@ -1,110 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var array = require( '@stdlib/ndarray-array' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} ndims - number of dimensions to which to broadcast -* @returns {Function} benchmark function -*/ -function createBenchmark( ndims ) { - var shape; - var sh; - var x; - var i; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - sh = x.shape; - - shape = []; - for ( i = 0; i < ndims; i++ ) { - shape.push( 0 ); - } - for ( i = ndims; i >= 1; i-- ) { - if ( i > sh.length ) { - shape[ ndims-i ] = 5; - } else { - shape[ ndims-i ] = sh[ i-1 ]; - } - } - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( x, shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var min; - var max; - var f; - var i; - - min = 2; - max = 10; - - for ( i = min; i <= max; i++ ) { - f = createBenchmark( i ); - bench( pkg+'::ndarray,2d:from_ndims=2,to_ndims='+i, f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index 90d11e3..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/maybe-broadcast-array" -%% click B href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/maybe-broadcast-array -[production-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 71859ce..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import maybeBroadcastArray from '../docs/types/index'; -export = maybeBroadcastArray; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 4b04e84..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var o=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var s=o(function(l,n){ -var u=require('@stdlib/ndarray-base-broadcast-array/dist'),v=require('@stdlib/ndarray-base-shape/dist');function c(e,r){var i,a,t;if(a=r.length,i=v(e,!1),i.length===a){for(t=0;t\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nmodule.exports = maybeBroadcastArray;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape.\n*\n* @module @stdlib/ndarray-base-maybe-broadcast-array\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var maybeBroadcastArray = require( '@stdlib/ndarray-base-maybe-broadcast-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAY,QAAS,sCAAuC,EAC5DC,EAAW,QAAS,4BAA6B,EA8DrD,SAASC,EAAqBC,EAAKC,EAAQ,CAC1C,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAM,OACVC,EAAKJ,EAAUE,EAAK,EAAM,EAGrBE,EAAG,SAAWC,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,CAAE,IAAMH,EAAOG,CAAE,EAEzB,OAAOP,EAAWG,EAAKC,CAAM,EAG/B,OAAOD,CACR,CAEA,OAAOH,EAAWG,EAAKC,CAAM,CAC9B,CAKAL,EAAO,QAAUG,ICjDjB,IAAIM,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "broadcast", "getShape", "maybeBroadcastArray", "arr", "shape", "sh", "N", "i", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 01ecba8..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,68 +0,0 @@ - -{{alias}}( arr, shape ) - Broadcasts an ndarray to a specified shape if and only if the specified - shape differs from the provided ndarray's shape. - - If a provided ndarray has the same shape as the specified shape, the - function returns the provided ndarray. - - If a provided ndarray has a different (broadcast compatible) shape than the - specified shape, the function returns a new (base) ndarray view of the - provided ndarray's data. The view is typically **not** contiguous. As more - than one element of a returned view may refer to the same memory location, - writing to the view may affect multiple elements. If you need to write to - the returned array, copy the array before performing operations which may - mutate elements. - - A returned array view is a "base" ndarray, and, thus, a returned array view - does not perform bounds checking or afford any of the guarantees of the non- - base ndarray constructor. The primary intent of this function is to - broadcast an ndarray-like object within internal implementations and to do - so with minimal overhead. - - The function throws an error if a provided ndarray is incompatible with a - provided shape. - - Parameters - ---------- - arr: ndarray - Input array. - - shape: ArrayLikeObject - Desired shape. - - Returns - ------- - out: ndarray - Broadcasted array. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > var sh = x.shape - [ 2, 2 ] - > var y = {{alias}}( x, [ 3, 2, 2 ] ) - - > sh = y.shape - [ 3, 2, 2 ] - > var v = y.get( 0, 0, 0 ) - 1 - > v = y.get( 0, 0, 1 ) - 2 - > v = y.get( 0, 1, 0 ) - 3 - > v = y.get( 0, 1, 1 ) - 4 - > v = y.get( 1, 0, 0 ) - 1 - > v = y.get( 1, 1, 0 ) - 3 - > v = y.get( 2, 0, 0 ) - 1 - > v = y.get( 2, 1, 1 ) - 4 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index d7a1a62..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,94 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ndarray } from '@stdlib/types/ndarray'; -import maybeBroadcastArray = require( './index' ); - -/** -* Mock function to create an ndarray-like object. -* -* @return ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns an ndarray... -{ - const x = array(); - - maybeBroadcastArray( x, [ 2, 2, 2 ] ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is not provided a first argument which is an ndarray... -{ - maybeBroadcastArray( '5', [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( 5, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( true, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( false, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( null, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( {}, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( [ '5' ], [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( ( x: number ): number => x, [ 2, 2, 2 ] ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a second argument which is an array-like object containing numbers... -{ - const x = array(); - - maybeBroadcastArray( x, '5' ); // $ExpectError - maybeBroadcastArray( x, 5 ); // $ExpectError - maybeBroadcastArray( x, true ); // $ExpectError - maybeBroadcastArray( x, false ); // $ExpectError - maybeBroadcastArray( x, null ); // $ExpectError - maybeBroadcastArray( x, {} ); // $ExpectError - maybeBroadcastArray( x, [ '5' ] ); // $ExpectError - maybeBroadcastArray( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - - maybeBroadcastArray(); // $ExpectError - maybeBroadcastArray( x ); // $ExpectError - maybeBroadcastArray( x, [ 1, 2, 3 ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index e787d6e..0000000 --- a/examples/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 array = require( '@stdlib/ndarray-array' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var maybeBroadcastArray = require( './../lib' ); - -// Create a 2x2 array: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -// returns - -// Broadcast the array to 3x2x2: -var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -// returns - -// Retrieve the shape: -var sh = y.shape; -// returns [ 3, 2, 2 ] - -// Retrieve the number of elements: -var N = numel( sh ); - -// Loop through the array elements... -var i; -for ( i = 0; i < N; i++ ) { - console.log( 'Y[%s] = %d', ind2sub( sh, i ).join( ', ' ), y.iget( i ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 97% rename from docs/types/index.d.ts rename to index.d.ts index c5bf290..69168e4 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..6ede144 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.1.0-esm/index.mjs";function e(e,s){var n,a,d;if(a=s.length,(n=t(e,!1)).length===a){for(d=0;d\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArray;\n"],"names":["maybeBroadcastArray","arr","shape","sh","N","i","length","getShape","broadcast"],"mappings":";;6LAqFA,SAASA,EAAqBC,EAAKC,GAClC,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAMI,QACVH,EAAKI,EAAUN,GAAK,IAGZK,SAAWF,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,KAAQH,EAAOG,GAEvB,OAAOG,EAAWP,EAAKC,GAGzB,OAAOD,CACP,CAED,OAAOO,EAAWP,EAAKC,EACxB"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 834e930..0000000 --- a/lib/index.js +++ /dev/null @@ -1,68 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* @module @stdlib/ndarray-base-maybe-broadcast-array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var maybeBroadcastArray = require( '@stdlib/ndarray-base-maybe-broadcast-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -*/ - -// 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 e59ca1d..0000000 --- a/lib/main.js +++ /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. -*/ - -'use strict'; - -// MODULES // - -var broadcast = require( '@stdlib/ndarray-base-broadcast-array' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); - - -// MAIN // - -/** -* Broadcasts an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* ## Notes -* -* - If a provided ndarray has the same shape as the specified shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the specified shape, the function returns a new (base) ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to the view may affect multiple elements. If you need to write to the returned array, copy the array before performing operations which may mutate elements. -* -* @param {ndarray} arr - input array -* @param {NonNegativeIntegerArray} shape - desired shape -* @throws {Error} input array cannot have more dimensions than the desired shape -* @throws {Error} input array dimension sizes must be `1` or equal to the corresponding dimension in the provided shape -* @throws {Error} input array and desired shape must be broadcast compatible -* @returns {ndarray} broadcasted array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var y = maybeBroadcastArray( x, [ 3, 2 ] ); -* // throws -*/ -function maybeBroadcastArray( arr, shape ) { - var sh; - var N; - var i; - - N = shape.length; - sh = getShape( arr, false ); - - // Check whether we need to broadcast the input array... - if ( sh.length === N ) { - for ( i = 0; i < N; i++ ) { - // Check whether dimensions match... - if ( sh[ i ] !== shape[ i ] ) { - // We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape... - return broadcast( arr, shape ); - } - } - return arr; - } - // If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape... - return broadcast( arr, shape ); -} - - -// EXPORTS // - -module.exports = maybeBroadcastArray; diff --git a/package.json b/package.json index b4246f2..b74d597 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Broadcast an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's 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", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-base-broadcast-array": "^0.1.0", - "@stdlib/ndarray-base-shape": "^0.1.0", - "@stdlib/types": "^0.2.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.1.1", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-base-ctor": "^0.1.0", - "@stdlib/ndarray-base-numel": "^0.1.1", - "@stdlib/ndarray-ctor": "^0.1.0", - "@stdlib/ndarray-ind2sub": "^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", @@ -86,9 +29,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..ba93b52 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 7e8e63f..0000000 --- a/test/test.js +++ /dev/null @@ -1,514 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 array = require( '@stdlib/ndarray-array' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var maybeBroadcastArray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof maybeBroadcastArray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a desired shape which has fewer dimensions than the input array', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 ] - }); - - values = [ - [], - [ 2 ], - [ 2, 2 ], - [ 2, 2, 2 ], - [ 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2, 2, 2 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided a shape with '+values[ i ].length+' dimension' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape having a dimension whose size is less than the corresponding dimension in the input array', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 10, 1 ], - [ 10, 10, 2 ], - [ 10, 10, 9 ], - [ 10, 1, 10 ], - [ 10, 2, 10 ], - [ 10, 9, 10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape and an input array shape which are broadcast-incompatible', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 20, 10 ], - [ 10, 10, 100 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function returns a "base" ndarray instance', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = maybeBroadcastArray( x, [ 2, 2, 2 ] ); - - t.notEqual( y, x, 'returns new instance' ); - t.strictEqual( y instanceof ndarray, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view over the input array data buffer', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = maybeBroadcastArray( x, [ 2, 2, 2 ] ); - - t.strictEqual( y.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; strides)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, -1 ], 3, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; strides)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, 1 ], 2, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; non-contiguous)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ 4, 2 ], 1, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 5 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 7 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (column-major)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'column-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (same shape)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2, 2 ], - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - // Should return the same instance: - t.strictEqual( y, x, 'returns expected value' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 1, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 1, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (same number of dimensions)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1, 2 ], - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (singleton dimension)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (singleton dimension)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 1, 2 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (0-dimensional array)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1 ]; - x = ndarray( 'generic', data, [], [ 0 ], 0, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); From ecb4f77a46245a9e1887f3e589a0d47568a979ac Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Feb 2024 08:25:48 +0000 Subject: [PATCH 061/119] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 9777183..b4246f2 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,8 @@ "dependencies": { "@stdlib/ndarray-base-broadcast-array": "^0.1.0", "@stdlib/ndarray-base-shape": "^0.1.0", - "@stdlib/types": "^0.2.0" + "@stdlib/types": "^0.2.0", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1" }, "devDependencies": { "@stdlib/array-float64": "^0.1.1", @@ -90,4 +91,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From f7058093d461f23364e10376aa09b9074d013308 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Feb 2024 13:48:27 +0000 Subject: [PATCH 062/119] Remove files --- index.d.ts | 81 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6263 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 69168e4..0000000 --- a/index.d.ts +++ /dev/null @@ -1,81 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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'; -import { ndarray } from '@stdlib/types/ndarray'; - -/** -* Broadcasts an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* ## Notes -* -* - The function throws an error if a provided ndarray is incompatible with a provided shape. -* - If a provided ndarray has the same shape as the specified shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the specified shape, the function returns a new (base) ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to the view may affect multiple elements. If you need to write to the returned array, copy the array before performing operations which may mutate elements. -* - A returned array view is a "base" ndarray, and, thus, a returned array view does not perform bounds checking or afford any of the guarantees of the non-base ndarray constructor. The primary intent of this function is to broadcast an ndarray-like object within internal implementations and to do so with minimal overhead. -* -* @param arr - input array -* @param shape - desired shape -* @throws input array cannot have more dimensions than the desired shape -* @throws input array dimension sizes must be `1` or equal to the corresponding dimension in the provided shape -* @throws input array and desired shape must be broadcast compatible -* @returns broadcasted array -* -* @example -* var array = require( `@stdlib/ndarray/array` ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -*/ -declare function maybeBroadcastArray( arr: ndarray, shape: ArrayLike ): ndarray; - - -// EXPORTS // - -export = maybeBroadcastArray; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 6ede144..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.1.0-esm/index.mjs";function e(e,s){var n,a,d;if(a=s.length,(n=t(e,!1)).length===a){for(d=0;d\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArray;\n"],"names":["maybeBroadcastArray","arr","shape","sh","N","i","length","getShape","broadcast"],"mappings":";;6LAqFA,SAASA,EAAqBC,EAAKC,GAClC,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAMI,QACVH,EAAKI,EAAUN,GAAK,IAGZK,SAAWF,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,KAAQH,EAAOG,GAEvB,OAAOG,EAAWP,EAAKC,GAGzB,OAAOD,CACP,CAED,OAAOO,EAAWP,EAAKC,EACxB"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index ba93b52..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 6f70bfbbaf299167b3fb8d0958e916dd54e3a2b6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Feb 2024 13:48:46 +0000 Subject: [PATCH 063/119] 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 | 49 +- SECURITY.md | 5 - benchmark/benchmark.js | 290 - benchmark/benchmark.ndims.js | 110 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 68 - docs/types/test.ts | 94 - examples/index.js | 45 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 68 - lib/main.js | 112 - package.json | 64 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 514 -- 44 files changed, 6206 insertions(+), 4665 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/benchmark.ndims.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (97%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/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 e93642c..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-02-01T05:54:30.240Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 740d5ce..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/maybe-broadcast-array) 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 4fadc31..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/maybe-broadcast-array) 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 e33a55c..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: '45 9 * * 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 + + ```
@@ -173,7 +164,7 @@ for ( i = 0; i < N; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -236,11 +227,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-maybe-broadcast-array/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor +[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor/tree/esm -[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes +[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm
diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index ba5f734..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,290 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var ndarrayBase = require( '@stdlib/ndarray-base-ctor' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArray = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::base_ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::base_ndarray,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( out.shape[ 0 ] !== shape[ 0 ] ) { - b.fail( 'unexpected result' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.ndims.js b/benchmark/benchmark.ndims.js deleted file mode 100644 index 739b74c..0000000 --- a/benchmark/benchmark.ndims.js +++ /dev/null @@ -1,110 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var array = require( '@stdlib/ndarray-array' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} ndims - number of dimensions to which to broadcast -* @returns {Function} benchmark function -*/ -function createBenchmark( ndims ) { - var shape; - var sh; - var x; - var i; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - sh = x.shape; - - shape = []; - for ( i = 0; i < ndims; i++ ) { - shape.push( 0 ); - } - for ( i = ndims; i >= 1; i-- ) { - if ( i > sh.length ) { - shape[ ndims-i ] = 5; - } else { - shape[ ndims-i ] = sh[ i-1 ]; - } - } - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( x, shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var min; - var max; - var f; - var i; - - min = 2; - max = 10; - - for ( i = min; i <= max; i++ ) { - f = createBenchmark( i ); - bench( pkg+'::ndarray,2d:from_ndims=2,to_ndims='+i, f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index e45b5c4..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/maybe-broadcast-array" -%% click B href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/maybe-broadcast-array -[production-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 71859ce..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import maybeBroadcastArray from '../docs/types/index'; -export = maybeBroadcastArray; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 4b04e84..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var o=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var s=o(function(l,n){ -var u=require('@stdlib/ndarray-base-broadcast-array/dist'),v=require('@stdlib/ndarray-base-shape/dist');function c(e,r){var i,a,t;if(a=r.length,i=v(e,!1),i.length===a){for(t=0;t\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nmodule.exports = maybeBroadcastArray;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape.\n*\n* @module @stdlib/ndarray-base-maybe-broadcast-array\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var maybeBroadcastArray = require( '@stdlib/ndarray-base-maybe-broadcast-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAY,QAAS,sCAAuC,EAC5DC,EAAW,QAAS,4BAA6B,EA8DrD,SAASC,EAAqBC,EAAKC,EAAQ,CAC1C,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAM,OACVC,EAAKJ,EAAUE,EAAK,EAAM,EAGrBE,EAAG,SAAWC,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,CAAE,IAAMH,EAAOG,CAAE,EAEzB,OAAOP,EAAWG,EAAKC,CAAM,EAG/B,OAAOD,CACR,CAEA,OAAOH,EAAWG,EAAKC,CAAM,CAC9B,CAKAL,EAAO,QAAUG,ICjDjB,IAAIM,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "broadcast", "getShape", "maybeBroadcastArray", "arr", "shape", "sh", "N", "i", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 01ecba8..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,68 +0,0 @@ - -{{alias}}( arr, shape ) - Broadcasts an ndarray to a specified shape if and only if the specified - shape differs from the provided ndarray's shape. - - If a provided ndarray has the same shape as the specified shape, the - function returns the provided ndarray. - - If a provided ndarray has a different (broadcast compatible) shape than the - specified shape, the function returns a new (base) ndarray view of the - provided ndarray's data. The view is typically **not** contiguous. As more - than one element of a returned view may refer to the same memory location, - writing to the view may affect multiple elements. If you need to write to - the returned array, copy the array before performing operations which may - mutate elements. - - A returned array view is a "base" ndarray, and, thus, a returned array view - does not perform bounds checking or afford any of the guarantees of the non- - base ndarray constructor. The primary intent of this function is to - broadcast an ndarray-like object within internal implementations and to do - so with minimal overhead. - - The function throws an error if a provided ndarray is incompatible with a - provided shape. - - Parameters - ---------- - arr: ndarray - Input array. - - shape: ArrayLikeObject - Desired shape. - - Returns - ------- - out: ndarray - Broadcasted array. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > var sh = x.shape - [ 2, 2 ] - > var y = {{alias}}( x, [ 3, 2, 2 ] ) - - > sh = y.shape - [ 3, 2, 2 ] - > var v = y.get( 0, 0, 0 ) - 1 - > v = y.get( 0, 0, 1 ) - 2 - > v = y.get( 0, 1, 0 ) - 3 - > v = y.get( 0, 1, 1 ) - 4 - > v = y.get( 1, 0, 0 ) - 1 - > v = y.get( 1, 1, 0 ) - 3 - > v = y.get( 2, 0, 0 ) - 1 - > v = y.get( 2, 1, 1 ) - 4 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index d7a1a62..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,94 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ndarray } from '@stdlib/types/ndarray'; -import maybeBroadcastArray = require( './index' ); - -/** -* Mock function to create an ndarray-like object. -* -* @return ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns an ndarray... -{ - const x = array(); - - maybeBroadcastArray( x, [ 2, 2, 2 ] ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is not provided a first argument which is an ndarray... -{ - maybeBroadcastArray( '5', [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( 5, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( true, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( false, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( null, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( {}, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( [ '5' ], [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( ( x: number ): number => x, [ 2, 2, 2 ] ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a second argument which is an array-like object containing numbers... -{ - const x = array(); - - maybeBroadcastArray( x, '5' ); // $ExpectError - maybeBroadcastArray( x, 5 ); // $ExpectError - maybeBroadcastArray( x, true ); // $ExpectError - maybeBroadcastArray( x, false ); // $ExpectError - maybeBroadcastArray( x, null ); // $ExpectError - maybeBroadcastArray( x, {} ); // $ExpectError - maybeBroadcastArray( x, [ '5' ] ); // $ExpectError - maybeBroadcastArray( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - - maybeBroadcastArray(); // $ExpectError - maybeBroadcastArray( x ); // $ExpectError - maybeBroadcastArray( x, [ 1, 2, 3 ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index e787d6e..0000000 --- a/examples/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 array = require( '@stdlib/ndarray-array' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var maybeBroadcastArray = require( './../lib' ); - -// Create a 2x2 array: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -// returns - -// Broadcast the array to 3x2x2: -var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -// returns - -// Retrieve the shape: -var sh = y.shape; -// returns [ 3, 2, 2 ] - -// Retrieve the number of elements: -var N = numel( sh ); - -// Loop through the array elements... -var i; -for ( i = 0; i < N; i++ ) { - console.log( 'Y[%s] = %d', ind2sub( sh, i ).join( ', ' ), y.iget( i ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 97% rename from docs/types/index.d.ts rename to index.d.ts index f354818..97640ae 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..6ede144 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.1.0-esm/index.mjs";function e(e,s){var n,a,d;if(a=s.length,(n=t(e,!1)).length===a){for(d=0;d\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArray;\n"],"names":["maybeBroadcastArray","arr","shape","sh","N","i","length","getShape","broadcast"],"mappings":";;6LAqFA,SAASA,EAAqBC,EAAKC,GAClC,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAMI,QACVH,EAAKI,EAAUN,GAAK,IAGZK,SAAWF,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,KAAQH,EAAOG,GAEvB,OAAOG,EAAWP,EAAKC,GAGzB,OAAOD,CACP,CAED,OAAOO,EAAWP,EAAKC,EACxB"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 834e930..0000000 --- a/lib/index.js +++ /dev/null @@ -1,68 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* @module @stdlib/ndarray-base-maybe-broadcast-array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var maybeBroadcastArray = require( '@stdlib/ndarray-base-maybe-broadcast-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -*/ - -// 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 e59ca1d..0000000 --- a/lib/main.js +++ /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. -*/ - -'use strict'; - -// MODULES // - -var broadcast = require( '@stdlib/ndarray-base-broadcast-array' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); - - -// MAIN // - -/** -* Broadcasts an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* ## Notes -* -* - If a provided ndarray has the same shape as the specified shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the specified shape, the function returns a new (base) ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to the view may affect multiple elements. If you need to write to the returned array, copy the array before performing operations which may mutate elements. -* -* @param {ndarray} arr - input array -* @param {NonNegativeIntegerArray} shape - desired shape -* @throws {Error} input array cannot have more dimensions than the desired shape -* @throws {Error} input array dimension sizes must be `1` or equal to the corresponding dimension in the provided shape -* @throws {Error} input array and desired shape must be broadcast compatible -* @returns {ndarray} broadcasted array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var y = maybeBroadcastArray( x, [ 3, 2 ] ); -* // throws -*/ -function maybeBroadcastArray( arr, shape ) { - var sh; - var N; - var i; - - N = shape.length; - sh = getShape( arr, false ); - - // Check whether we need to broadcast the input array... - if ( sh.length === N ) { - for ( i = 0; i < N; i++ ) { - // Check whether dimensions match... - if ( sh[ i ] !== shape[ i ] ) { - // We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape... - return broadcast( arr, shape ); - } - } - return arr; - } - // If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape... - return broadcast( arr, shape ); -} - - -// EXPORTS // - -module.exports = maybeBroadcastArray; diff --git a/package.json b/package.json index b4246f2..b74d597 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Broadcast an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's 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", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-base-broadcast-array": "^0.1.0", - "@stdlib/ndarray-base-shape": "^0.1.0", - "@stdlib/types": "^0.2.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.1.1", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-base-ctor": "^0.1.0", - "@stdlib/ndarray-base-numel": "^0.1.1", - "@stdlib/ndarray-ctor": "^0.1.0", - "@stdlib/ndarray-ind2sub": "^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", @@ -86,9 +29,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..47a03ba --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 7e8e63f..0000000 --- a/test/test.js +++ /dev/null @@ -1,514 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 array = require( '@stdlib/ndarray-array' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var maybeBroadcastArray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof maybeBroadcastArray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a desired shape which has fewer dimensions than the input array', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 ] - }); - - values = [ - [], - [ 2 ], - [ 2, 2 ], - [ 2, 2, 2 ], - [ 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2, 2, 2 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided a shape with '+values[ i ].length+' dimension' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape having a dimension whose size is less than the corresponding dimension in the input array', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 10, 1 ], - [ 10, 10, 2 ], - [ 10, 10, 9 ], - [ 10, 1, 10 ], - [ 10, 2, 10 ], - [ 10, 9, 10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape and an input array shape which are broadcast-incompatible', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 20, 10 ], - [ 10, 10, 100 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function returns a "base" ndarray instance', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = maybeBroadcastArray( x, [ 2, 2, 2 ] ); - - t.notEqual( y, x, 'returns new instance' ); - t.strictEqual( y instanceof ndarray, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view over the input array data buffer', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = maybeBroadcastArray( x, [ 2, 2, 2 ] ); - - t.strictEqual( y.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; strides)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, -1 ], 3, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; strides)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, 1 ], 2, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; non-contiguous)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ 4, 2 ], 1, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 5 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 7 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (column-major)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'column-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (same shape)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2, 2 ], - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - // Should return the same instance: - t.strictEqual( y, x, 'returns expected value' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 1, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 1, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (same number of dimensions)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1, 2 ], - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (singleton dimension)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (singleton dimension)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 1, 2 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (0-dimensional array)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1 ]; - x = ndarray( 'generic', data, [], [ 0 ], 0, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); From 9c803c0f13318a76ac08a97e777504eefe5e301c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 14 Feb 2024 23:57:34 +0000 Subject: [PATCH 064/119] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index fb32c0f..03e70ed 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,8 @@ "dependencies": { "@stdlib/ndarray-base-broadcast-array": "^0.2.0", "@stdlib/ndarray-base-shape": "^0.2.0", - "@stdlib/types": "^0.3.1" + "@stdlib/types": "^0.3.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.0" }, "devDependencies": { "@stdlib/array-float64": "^0.2.0", @@ -90,4 +91,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From 9bac6604da6ef86471131eef154ee1bbdc48334a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 02:30:38 +0000 Subject: [PATCH 065/119] Remove files --- index.d.ts | 81 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6263 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 97640ae..0000000 --- a/index.d.ts +++ /dev/null @@ -1,81 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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'; -import { ndarray } from '@stdlib/types/ndarray'; - -/** -* Broadcasts an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* ## Notes -* -* - The function throws an error if a provided ndarray is incompatible with a provided shape. -* - If a provided ndarray has the same shape as the specified shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the specified shape, the function returns a new (base) ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to the view may affect multiple elements. If you need to write to the returned array, copy the array before performing operations which may mutate elements. -* - A returned array view is a "base" ndarray, and, thus, a returned array view does not perform bounds checking or afford any of the guarantees of the non-base ndarray constructor. The primary intent of this function is to broadcast an ndarray-like object within internal implementations and to do so with minimal overhead. -* -* @param arr - input array -* @param shape - desired shape -* @throws input array cannot have more dimensions than the desired shape -* @throws input array dimension sizes must be `1` or equal to the corresponding dimension in the provided shape -* @throws input array and desired shape must be broadcast compatible -* @returns broadcasted array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -*/ -declare function maybeBroadcastArray( arr: ndarray, shape: ArrayLike ): ndarray; - - -// EXPORTS // - -export = maybeBroadcastArray; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 6ede144..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.1.0-esm/index.mjs";function e(e,s){var n,a,d;if(a=s.length,(n=t(e,!1)).length===a){for(d=0;d\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArray;\n"],"names":["maybeBroadcastArray","arr","shape","sh","N","i","length","getShape","broadcast"],"mappings":";;6LAqFA,SAASA,EAAqBC,EAAKC,GAClC,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAMI,QACVH,EAAKI,EAAUN,GAAK,IAGZK,SAAWF,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,KAAQH,EAAOG,GAEvB,OAAOG,EAAWP,EAAKC,GAGzB,OAAOD,CACP,CAED,OAAOO,EAAWP,EAAKC,EACxB"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 47a03ba..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From b8f3fb345af4d392d81a7bc47f4712cc6367da49 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 02:31:27 +0000 Subject: [PATCH 066/119] 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 | 49 +- SECURITY.md | 5 - benchmark/benchmark.js | 290 - benchmark/benchmark.ndims.js | 110 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 68 - docs/types/test.ts | 94 - examples/index.js | 45 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 68 - lib/main.js | 112 - package.json | 64 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 514 -- 43 files changed, 6206 insertions(+), 4668 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/benchmark.ndims.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (97%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/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 740d5ce..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/maybe-broadcast-array) 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 4fadc31..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/maybe-broadcast-array) 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 8869da9..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: '45 9 * * 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 + + ```
@@ -173,7 +164,7 @@ for ( i = 0; i < N; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -236,11 +227,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-maybe-broadcast-array/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor +[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor/tree/esm -[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes +[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm
diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index ba5f734..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,290 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var ndarrayBase = require( '@stdlib/ndarray-base-ctor' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArray = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::base_ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::base_ndarray,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( out.shape[ 0 ] !== shape[ 0 ] ) { - b.fail( 'unexpected result' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.ndims.js b/benchmark/benchmark.ndims.js deleted file mode 100644 index 739b74c..0000000 --- a/benchmark/benchmark.ndims.js +++ /dev/null @@ -1,110 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var array = require( '@stdlib/ndarray-array' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} ndims - number of dimensions to which to broadcast -* @returns {Function} benchmark function -*/ -function createBenchmark( ndims ) { - var shape; - var sh; - var x; - var i; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - sh = x.shape; - - shape = []; - for ( i = 0; i < ndims; i++ ) { - shape.push( 0 ); - } - for ( i = ndims; i >= 1; i-- ) { - if ( i > sh.length ) { - shape[ ndims-i ] = 5; - } else { - shape[ ndims-i ] = sh[ i-1 ]; - } - } - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( x, shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var min; - var max; - var f; - var i; - - min = 2; - max = 10; - - for ( i = min; i <= max; i++ ) { - f = createBenchmark( i ); - bench( pkg+'::ndarray,2d:from_ndims=2,to_ndims='+i, f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index e45b5c4..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/maybe-broadcast-array" -%% click B href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/maybe-broadcast-array -[production-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 71859ce..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import maybeBroadcastArray from '../docs/types/index'; -export = maybeBroadcastArray; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 4b04e84..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var o=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var s=o(function(l,n){ -var u=require('@stdlib/ndarray-base-broadcast-array/dist'),v=require('@stdlib/ndarray-base-shape/dist');function c(e,r){var i,a,t;if(a=r.length,i=v(e,!1),i.length===a){for(t=0;t\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nmodule.exports = maybeBroadcastArray;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape.\n*\n* @module @stdlib/ndarray-base-maybe-broadcast-array\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var maybeBroadcastArray = require( '@stdlib/ndarray-base-maybe-broadcast-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAY,QAAS,sCAAuC,EAC5DC,EAAW,QAAS,4BAA6B,EA8DrD,SAASC,EAAqBC,EAAKC,EAAQ,CAC1C,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAM,OACVC,EAAKJ,EAAUE,EAAK,EAAM,EAGrBE,EAAG,SAAWC,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,CAAE,IAAMH,EAAOG,CAAE,EAEzB,OAAOP,EAAWG,EAAKC,CAAM,EAG/B,OAAOD,CACR,CAEA,OAAOH,EAAWG,EAAKC,CAAM,CAC9B,CAKAL,EAAO,QAAUG,ICjDjB,IAAIM,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "broadcast", "getShape", "maybeBroadcastArray", "arr", "shape", "sh", "N", "i", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 01ecba8..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,68 +0,0 @@ - -{{alias}}( arr, shape ) - Broadcasts an ndarray to a specified shape if and only if the specified - shape differs from the provided ndarray's shape. - - If a provided ndarray has the same shape as the specified shape, the - function returns the provided ndarray. - - If a provided ndarray has a different (broadcast compatible) shape than the - specified shape, the function returns a new (base) ndarray view of the - provided ndarray's data. The view is typically **not** contiguous. As more - than one element of a returned view may refer to the same memory location, - writing to the view may affect multiple elements. If you need to write to - the returned array, copy the array before performing operations which may - mutate elements. - - A returned array view is a "base" ndarray, and, thus, a returned array view - does not perform bounds checking or afford any of the guarantees of the non- - base ndarray constructor. The primary intent of this function is to - broadcast an ndarray-like object within internal implementations and to do - so with minimal overhead. - - The function throws an error if a provided ndarray is incompatible with a - provided shape. - - Parameters - ---------- - arr: ndarray - Input array. - - shape: ArrayLikeObject - Desired shape. - - Returns - ------- - out: ndarray - Broadcasted array. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > var sh = x.shape - [ 2, 2 ] - > var y = {{alias}}( x, [ 3, 2, 2 ] ) - - > sh = y.shape - [ 3, 2, 2 ] - > var v = y.get( 0, 0, 0 ) - 1 - > v = y.get( 0, 0, 1 ) - 2 - > v = y.get( 0, 1, 0 ) - 3 - > v = y.get( 0, 1, 1 ) - 4 - > v = y.get( 1, 0, 0 ) - 1 - > v = y.get( 1, 1, 0 ) - 3 - > v = y.get( 2, 0, 0 ) - 1 - > v = y.get( 2, 1, 1 ) - 4 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index d7a1a62..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,94 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ndarray } from '@stdlib/types/ndarray'; -import maybeBroadcastArray = require( './index' ); - -/** -* Mock function to create an ndarray-like object. -* -* @return ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns an ndarray... -{ - const x = array(); - - maybeBroadcastArray( x, [ 2, 2, 2 ] ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is not provided a first argument which is an ndarray... -{ - maybeBroadcastArray( '5', [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( 5, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( true, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( false, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( null, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( {}, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( [ '5' ], [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( ( x: number ): number => x, [ 2, 2, 2 ] ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a second argument which is an array-like object containing numbers... -{ - const x = array(); - - maybeBroadcastArray( x, '5' ); // $ExpectError - maybeBroadcastArray( x, 5 ); // $ExpectError - maybeBroadcastArray( x, true ); // $ExpectError - maybeBroadcastArray( x, false ); // $ExpectError - maybeBroadcastArray( x, null ); // $ExpectError - maybeBroadcastArray( x, {} ); // $ExpectError - maybeBroadcastArray( x, [ '5' ] ); // $ExpectError - maybeBroadcastArray( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - - maybeBroadcastArray(); // $ExpectError - maybeBroadcastArray( x ); // $ExpectError - maybeBroadcastArray( x, [ 1, 2, 3 ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index e787d6e..0000000 --- a/examples/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 array = require( '@stdlib/ndarray-array' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var maybeBroadcastArray = require( './../lib' ); - -// Create a 2x2 array: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -// returns - -// Broadcast the array to 3x2x2: -var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -// returns - -// Retrieve the shape: -var sh = y.shape; -// returns [ 3, 2, 2 ] - -// Retrieve the number of elements: -var N = numel( sh ); - -// Loop through the array elements... -var i; -for ( i = 0; i < N; i++ ) { - console.log( 'Y[%s] = %d', ind2sub( sh, i ).join( ', ' ), y.iget( i ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 97% rename from docs/types/index.d.ts rename to index.d.ts index f354818..97640ae 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..6ede144 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.1.0-esm/index.mjs";function e(e,s){var n,a,d;if(a=s.length,(n=t(e,!1)).length===a){for(d=0;d\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArray;\n"],"names":["maybeBroadcastArray","arr","shape","sh","N","i","length","getShape","broadcast"],"mappings":";;6LAqFA,SAASA,EAAqBC,EAAKC,GAClC,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAMI,QACVH,EAAKI,EAAUN,GAAK,IAGZK,SAAWF,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,KAAQH,EAAOG,GAEvB,OAAOG,EAAWP,EAAKC,GAGzB,OAAOD,CACP,CAED,OAAOO,EAAWP,EAAKC,EACxB"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 834e930..0000000 --- a/lib/index.js +++ /dev/null @@ -1,68 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* @module @stdlib/ndarray-base-maybe-broadcast-array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var maybeBroadcastArray = require( '@stdlib/ndarray-base-maybe-broadcast-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -*/ - -// 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 e59ca1d..0000000 --- a/lib/main.js +++ /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. -*/ - -'use strict'; - -// MODULES // - -var broadcast = require( '@stdlib/ndarray-base-broadcast-array' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); - - -// MAIN // - -/** -* Broadcasts an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* ## Notes -* -* - If a provided ndarray has the same shape as the specified shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the specified shape, the function returns a new (base) ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to the view may affect multiple elements. If you need to write to the returned array, copy the array before performing operations which may mutate elements. -* -* @param {ndarray} arr - input array -* @param {NonNegativeIntegerArray} shape - desired shape -* @throws {Error} input array cannot have more dimensions than the desired shape -* @throws {Error} input array dimension sizes must be `1` or equal to the corresponding dimension in the provided shape -* @throws {Error} input array and desired shape must be broadcast compatible -* @returns {ndarray} broadcasted array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var y = maybeBroadcastArray( x, [ 3, 2 ] ); -* // throws -*/ -function maybeBroadcastArray( arr, shape ) { - var sh; - var N; - var i; - - N = shape.length; - sh = getShape( arr, false ); - - // Check whether we need to broadcast the input array... - if ( sh.length === N ) { - for ( i = 0; i < N; i++ ) { - // Check whether dimensions match... - if ( sh[ i ] !== shape[ i ] ) { - // We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape... - return broadcast( arr, shape ); - } - } - return arr; - } - // If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape... - return broadcast( arr, shape ); -} - - -// EXPORTS // - -module.exports = maybeBroadcastArray; diff --git a/package.json b/package.json index 03e70ed..6f0b2e4 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.0", "description": "Broadcast an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's 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", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-base-broadcast-array": "^0.2.0", - "@stdlib/ndarray-base-shape": "^0.2.0", - "@stdlib/types": "^0.3.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.0" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.2.0", - "@stdlib/assert-is-ndarray-like": "^0.2.0", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-base-ctor": "^0.2.0", - "@stdlib/ndarray-base-numel": "^0.2.0", - "@stdlib/ndarray-ctor": "^0.1.0", - "@stdlib/ndarray-ind2sub": "^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.2.0" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -86,9 +29,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..e009476 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 7e8e63f..0000000 --- a/test/test.js +++ /dev/null @@ -1,514 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 array = require( '@stdlib/ndarray-array' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var maybeBroadcastArray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof maybeBroadcastArray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a desired shape which has fewer dimensions than the input array', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 ] - }); - - values = [ - [], - [ 2 ], - [ 2, 2 ], - [ 2, 2, 2 ], - [ 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2, 2, 2 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided a shape with '+values[ i ].length+' dimension' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape having a dimension whose size is less than the corresponding dimension in the input array', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 10, 1 ], - [ 10, 10, 2 ], - [ 10, 10, 9 ], - [ 10, 1, 10 ], - [ 10, 2, 10 ], - [ 10, 9, 10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape and an input array shape which are broadcast-incompatible', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 20, 10 ], - [ 10, 10, 100 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function returns a "base" ndarray instance', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = maybeBroadcastArray( x, [ 2, 2, 2 ] ); - - t.notEqual( y, x, 'returns new instance' ); - t.strictEqual( y instanceof ndarray, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view over the input array data buffer', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = maybeBroadcastArray( x, [ 2, 2, 2 ] ); - - t.strictEqual( y.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; strides)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, -1 ], 3, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; strides)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, 1 ], 2, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; non-contiguous)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ 4, 2 ], 1, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 5 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 7 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (column-major)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'column-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (same shape)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2, 2 ], - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - // Should return the same instance: - t.strictEqual( y, x, 'returns expected value' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 1, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 1, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (same number of dimensions)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1, 2 ], - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (singleton dimension)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (singleton dimension)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 1, 2 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (0-dimensional array)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1 ]; - x = ndarray( 'generic', data, [], [ 0 ], 0, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); From aee5a88d679d2466de0ff20a308f22c4e4fa7546 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 04:14:54 +0000 Subject: [PATCH 067/119] Update README.md for ESM bundle v0.2.0 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3575b79..c7d15a3 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ limitations under the License. ## Usage ```javascript -import maybeBroadcastArray from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-maybe-broadcast-array@esm/index.mjs'; +import maybeBroadcastArray from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-maybe-broadcast-array@v0.2.0-esm/index.mjs'; ``` #### maybeBroadcastArray( arr, shape ) @@ -107,7 +107,7 @@ var y = maybeBroadcastArray( x, [ 2, 2, 2 ] ); import array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-array@esm/index.mjs'; import numel from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@esm/index.mjs'; import ind2sub from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ind2sub@esm/index.mjs'; -import maybeBroadcastArray from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-maybe-broadcast-array@esm/index.mjs'; +import maybeBroadcastArray from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-maybe-broadcast-array@v0.2.0-esm/index.mjs'; // Create a 2x2 array: var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); From 588f752f3d401cf468fc94559b450ec6463afc3a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 04:14:55 +0000 Subject: [PATCH 068/119] Auto-generated commit --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c7d15a3..7f3bfc7 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,11 @@ limitations under the License. ## Usage +```javascript +import maybeBroadcastArray from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-maybe-broadcast-array@esm/index.mjs'; +``` +The previous example will load the latest bundled code from the esm branch. Alternatively, you may load a specific version by loading the file from one of the [tagged bundles](https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tags). For example, + ```javascript import maybeBroadcastArray from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-maybe-broadcast-array@v0.2.0-esm/index.mjs'; ``` @@ -107,7 +112,7 @@ var y = maybeBroadcastArray( x, [ 2, 2, 2 ] ); import array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-array@esm/index.mjs'; import numel from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@esm/index.mjs'; import ind2sub from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ind2sub@esm/index.mjs'; -import maybeBroadcastArray from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-maybe-broadcast-array@v0.2.0-esm/index.mjs'; +import maybeBroadcastArray from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-maybe-broadcast-array@esm/index.mjs'; // Create a 2x2 array: var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); From b72cfb76d576bf184c945ceef7db25791c599119 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 18:53:12 +0000 Subject: [PATCH 069/119] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 71a1ba0..42ec755 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,8 @@ "dependencies": { "@stdlib/ndarray-base-broadcast-array": "^0.2.1", "@stdlib/ndarray-base-shape": "^0.2.1", - "@stdlib/types": "^0.3.2" + "@stdlib/types": "^0.3.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1" }, "devDependencies": { "@stdlib/array-float64": "^0.2.1", @@ -90,4 +91,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From 1efb214c52557ae475d8041682e777536ce58870 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 19:10:46 +0000 Subject: [PATCH 070/119] Remove files --- index.d.ts | 81 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6263 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 97640ae..0000000 --- a/index.d.ts +++ /dev/null @@ -1,81 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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'; -import { ndarray } from '@stdlib/types/ndarray'; - -/** -* Broadcasts an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* ## Notes -* -* - The function throws an error if a provided ndarray is incompatible with a provided shape. -* - If a provided ndarray has the same shape as the specified shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the specified shape, the function returns a new (base) ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to the view may affect multiple elements. If you need to write to the returned array, copy the array before performing operations which may mutate elements. -* - A returned array view is a "base" ndarray, and, thus, a returned array view does not perform bounds checking or afford any of the guarantees of the non-base ndarray constructor. The primary intent of this function is to broadcast an ndarray-like object within internal implementations and to do so with minimal overhead. -* -* @param arr - input array -* @param shape - desired shape -* @throws input array cannot have more dimensions than the desired shape -* @throws input array dimension sizes must be `1` or equal to the corresponding dimension in the provided shape -* @throws input array and desired shape must be broadcast compatible -* @returns broadcasted array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -*/ -declare function maybeBroadcastArray( arr: ndarray, shape: ArrayLike ): ndarray; - - -// EXPORTS // - -export = maybeBroadcastArray; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 6ede144..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.1.0-esm/index.mjs";function e(e,s){var n,a,d;if(a=s.length,(n=t(e,!1)).length===a){for(d=0;d\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArray;\n"],"names":["maybeBroadcastArray","arr","shape","sh","N","i","length","getShape","broadcast"],"mappings":";;6LAqFA,SAASA,EAAqBC,EAAKC,GAClC,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAMI,QACVH,EAAKI,EAAUN,GAAK,IAGZK,SAAWF,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,KAAQH,EAAOG,GAEvB,OAAOG,EAAWP,EAAKC,GAGzB,OAAOD,CACP,CAED,OAAOO,EAAWP,EAAKC,EACxB"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index e009476..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From a844cbe6e68ec3bd165344fef72685995c6b7873 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 19:11:09 +0000 Subject: [PATCH 071/119] 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 | 49 +- SECURITY.md | 5 - benchmark/benchmark.js | 290 -- benchmark/benchmark.ndims.js | 110 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 68 - docs/types/test.ts | 94 - examples/index.js | 45 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 68 - lib/main.js | 112 - package.json | 64 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 514 --- 43 files changed, 4871 insertions(+), 4662 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/benchmark.ndims.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (97%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/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 740d5ce..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/maybe-broadcast-array) 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 4fadc31..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/maybe-broadcast-array) 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 31edc84..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: '45 9 * * 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 + + ```
@@ -173,7 +164,7 @@ for ( i = 0; i < N; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -236,11 +227,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-maybe-broadcast-array/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor +[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor/tree/esm -[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes +[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm
diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index ba5f734..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,290 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var ndarrayBase = require( '@stdlib/ndarray-base-ctor' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArray = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::base_ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::base_ndarray,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( out.shape[ 0 ] !== shape[ 0 ] ) { - b.fail( 'unexpected result' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.ndims.js b/benchmark/benchmark.ndims.js deleted file mode 100644 index 739b74c..0000000 --- a/benchmark/benchmark.ndims.js +++ /dev/null @@ -1,110 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var array = require( '@stdlib/ndarray-array' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} ndims - number of dimensions to which to broadcast -* @returns {Function} benchmark function -*/ -function createBenchmark( ndims ) { - var shape; - var sh; - var x; - var i; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - sh = x.shape; - - shape = []; - for ( i = 0; i < ndims; i++ ) { - shape.push( 0 ); - } - for ( i = ndims; i >= 1; i-- ) { - if ( i > sh.length ) { - shape[ ndims-i ] = 5; - } else { - shape[ ndims-i ] = sh[ i-1 ]; - } - } - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( x, shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var min; - var max; - var f; - var i; - - min = 2; - max = 10; - - for ( i = min; i <= max; i++ ) { - f = createBenchmark( i ); - bench( pkg+'::ndarray,2d:from_ndims=2,to_ndims='+i, f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index e45b5c4..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/maybe-broadcast-array" -%% click B href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/maybe-broadcast-array -[production-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 71859ce..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import maybeBroadcastArray from '../docs/types/index'; -export = maybeBroadcastArray; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 4b04e84..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var o=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var s=o(function(l,n){ -var u=require('@stdlib/ndarray-base-broadcast-array/dist'),v=require('@stdlib/ndarray-base-shape/dist');function c(e,r){var i,a,t;if(a=r.length,i=v(e,!1),i.length===a){for(t=0;t\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nmodule.exports = maybeBroadcastArray;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape.\n*\n* @module @stdlib/ndarray-base-maybe-broadcast-array\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var maybeBroadcastArray = require( '@stdlib/ndarray-base-maybe-broadcast-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAY,QAAS,sCAAuC,EAC5DC,EAAW,QAAS,4BAA6B,EA8DrD,SAASC,EAAqBC,EAAKC,EAAQ,CAC1C,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAM,OACVC,EAAKJ,EAAUE,EAAK,EAAM,EAGrBE,EAAG,SAAWC,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,CAAE,IAAMH,EAAOG,CAAE,EAEzB,OAAOP,EAAWG,EAAKC,CAAM,EAG/B,OAAOD,CACR,CAEA,OAAOH,EAAWG,EAAKC,CAAM,CAC9B,CAKAL,EAAO,QAAUG,ICjDjB,IAAIM,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "broadcast", "getShape", "maybeBroadcastArray", "arr", "shape", "sh", "N", "i", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 01ecba8..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,68 +0,0 @@ - -{{alias}}( arr, shape ) - Broadcasts an ndarray to a specified shape if and only if the specified - shape differs from the provided ndarray's shape. - - If a provided ndarray has the same shape as the specified shape, the - function returns the provided ndarray. - - If a provided ndarray has a different (broadcast compatible) shape than the - specified shape, the function returns a new (base) ndarray view of the - provided ndarray's data. The view is typically **not** contiguous. As more - than one element of a returned view may refer to the same memory location, - writing to the view may affect multiple elements. If you need to write to - the returned array, copy the array before performing operations which may - mutate elements. - - A returned array view is a "base" ndarray, and, thus, a returned array view - does not perform bounds checking or afford any of the guarantees of the non- - base ndarray constructor. The primary intent of this function is to - broadcast an ndarray-like object within internal implementations and to do - so with minimal overhead. - - The function throws an error if a provided ndarray is incompatible with a - provided shape. - - Parameters - ---------- - arr: ndarray - Input array. - - shape: ArrayLikeObject - Desired shape. - - Returns - ------- - out: ndarray - Broadcasted array. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > var sh = x.shape - [ 2, 2 ] - > var y = {{alias}}( x, [ 3, 2, 2 ] ) - - > sh = y.shape - [ 3, 2, 2 ] - > var v = y.get( 0, 0, 0 ) - 1 - > v = y.get( 0, 0, 1 ) - 2 - > v = y.get( 0, 1, 0 ) - 3 - > v = y.get( 0, 1, 1 ) - 4 - > v = y.get( 1, 0, 0 ) - 1 - > v = y.get( 1, 1, 0 ) - 3 - > v = y.get( 2, 0, 0 ) - 1 - > v = y.get( 2, 1, 1 ) - 4 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index d7a1a62..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,94 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ndarray } from '@stdlib/types/ndarray'; -import maybeBroadcastArray = require( './index' ); - -/** -* Mock function to create an ndarray-like object. -* -* @return ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns an ndarray... -{ - const x = array(); - - maybeBroadcastArray( x, [ 2, 2, 2 ] ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is not provided a first argument which is an ndarray... -{ - maybeBroadcastArray( '5', [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( 5, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( true, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( false, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( null, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( {}, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( [ '5' ], [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( ( x: number ): number => x, [ 2, 2, 2 ] ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a second argument which is an array-like object containing numbers... -{ - const x = array(); - - maybeBroadcastArray( x, '5' ); // $ExpectError - maybeBroadcastArray( x, 5 ); // $ExpectError - maybeBroadcastArray( x, true ); // $ExpectError - maybeBroadcastArray( x, false ); // $ExpectError - maybeBroadcastArray( x, null ); // $ExpectError - maybeBroadcastArray( x, {} ); // $ExpectError - maybeBroadcastArray( x, [ '5' ] ); // $ExpectError - maybeBroadcastArray( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - - maybeBroadcastArray(); // $ExpectError - maybeBroadcastArray( x ); // $ExpectError - maybeBroadcastArray( x, [ 1, 2, 3 ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index e787d6e..0000000 --- a/examples/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 array = require( '@stdlib/ndarray-array' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var maybeBroadcastArray = require( './../lib' ); - -// Create a 2x2 array: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -// returns - -// Broadcast the array to 3x2x2: -var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -// returns - -// Retrieve the shape: -var sh = y.shape; -// returns [ 3, 2, 2 ] - -// Retrieve the number of elements: -var N = numel( sh ); - -// Loop through the array elements... -var i; -for ( i = 0; i < N; i++ ) { - console.log( 'Y[%s] = %d', ind2sub( sh, i ).join( ', ' ), y.iget( i ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 97% rename from docs/types/index.d.ts rename to index.d.ts index f354818..97640ae 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..9db3970 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@v0.2.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.0-esm/index.mjs";function e(e,s){var n,a,d;if(a=s.length,(n=t(e,!1)).length===a){for(d=0;d\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArray;\n"],"names":["maybeBroadcastArray","arr","shape","sh","N","i","length","getShape","broadcast"],"mappings":";;oMAqFA,SAASA,EAAqBC,EAAKC,GAClC,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAMI,QACVH,EAAKI,EAAUN,GAAK,IAGZK,SAAWF,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,KAAQH,EAAOG,GAEvB,OAAOG,EAAWP,EAAKC,GAGzB,OAAOD,CACP,CAED,OAAOO,EAAWP,EAAKC,EACxB"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 834e930..0000000 --- a/lib/index.js +++ /dev/null @@ -1,68 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* @module @stdlib/ndarray-base-maybe-broadcast-array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var maybeBroadcastArray = require( '@stdlib/ndarray-base-maybe-broadcast-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -*/ - -// 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 e59ca1d..0000000 --- a/lib/main.js +++ /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. -*/ - -'use strict'; - -// MODULES // - -var broadcast = require( '@stdlib/ndarray-base-broadcast-array' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); - - -// MAIN // - -/** -* Broadcasts an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* ## Notes -* -* - If a provided ndarray has the same shape as the specified shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the specified shape, the function returns a new (base) ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to the view may affect multiple elements. If you need to write to the returned array, copy the array before performing operations which may mutate elements. -* -* @param {ndarray} arr - input array -* @param {NonNegativeIntegerArray} shape - desired shape -* @throws {Error} input array cannot have more dimensions than the desired shape -* @throws {Error} input array dimension sizes must be `1` or equal to the corresponding dimension in the provided shape -* @throws {Error} input array and desired shape must be broadcast compatible -* @returns {ndarray} broadcasted array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var y = maybeBroadcastArray( x, [ 3, 2 ] ); -* // throws -*/ -function maybeBroadcastArray( arr, shape ) { - var sh; - var N; - var i; - - N = shape.length; - sh = getShape( arr, false ); - - // Check whether we need to broadcast the input array... - if ( sh.length === N ) { - for ( i = 0; i < N; i++ ) { - // Check whether dimensions match... - if ( sh[ i ] !== shape[ i ] ) { - // We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape... - return broadcast( arr, shape ); - } - } - return arr; - } - // If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape... - return broadcast( arr, shape ); -} - - -// EXPORTS // - -module.exports = maybeBroadcastArray; diff --git a/package.json b/package.json index 42ec755..823b56b 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Broadcast an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's 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", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-base-broadcast-array": "^0.2.1", - "@stdlib/ndarray-base-shape": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.2.1", - "@stdlib/assert-is-ndarray-like": "^0.2.1", - "@stdlib/ndarray-array": "^0.2.0", - "@stdlib/ndarray-base-ctor": "^0.2.1", - "@stdlib/ndarray-base-numel": "^0.2.1", - "@stdlib/ndarray-ctor": "^0.2.0", - "@stdlib/ndarray-ind2sub": "^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.1" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -86,9 +29,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..d5a7e7c --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 7e8e63f..0000000 --- a/test/test.js +++ /dev/null @@ -1,514 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 array = require( '@stdlib/ndarray-array' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var maybeBroadcastArray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof maybeBroadcastArray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a desired shape which has fewer dimensions than the input array', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 ] - }); - - values = [ - [], - [ 2 ], - [ 2, 2 ], - [ 2, 2, 2 ], - [ 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2, 2, 2 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided a shape with '+values[ i ].length+' dimension' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape having a dimension whose size is less than the corresponding dimension in the input array', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 10, 1 ], - [ 10, 10, 2 ], - [ 10, 10, 9 ], - [ 10, 1, 10 ], - [ 10, 2, 10 ], - [ 10, 9, 10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape and an input array shape which are broadcast-incompatible', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 20, 10 ], - [ 10, 10, 100 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function returns a "base" ndarray instance', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = maybeBroadcastArray( x, [ 2, 2, 2 ] ); - - t.notEqual( y, x, 'returns new instance' ); - t.strictEqual( y instanceof ndarray, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view over the input array data buffer', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = maybeBroadcastArray( x, [ 2, 2, 2 ] ); - - t.strictEqual( y.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; strides)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, -1 ], 3, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; strides)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, 1 ], 2, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; non-contiguous)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ 4, 2 ], 1, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 5 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 7 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (column-major)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'column-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (same shape)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2, 2 ], - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - // Should return the same instance: - t.strictEqual( y, x, 'returns expected value' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 1, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 1, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (same number of dimensions)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1, 2 ], - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (singleton dimension)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (singleton dimension)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 1, 2 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (0-dimensional array)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1 ]; - x = ndarray( 'generic', data, [], [ 0 ], 0, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); From 9fcc3356fba15240822c6313385938c1e2abdfe9 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 19:29:11 +0000 Subject: [PATCH 072/119] Update README.md for ESM bundle v0.2.1 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 64b06e3..4493151 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ limitations under the License. ## Usage ```javascript -import maybeBroadcastArray from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-maybe-broadcast-array@esm/index.mjs'; +import maybeBroadcastArray from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-maybe-broadcast-array@v0.2.1-esm/index.mjs'; ``` #### maybeBroadcastArray( arr, shape ) @@ -107,7 +107,7 @@ var y = maybeBroadcastArray( x, [ 2, 2, 2 ] ); import array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-array@esm/index.mjs'; import numel from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@esm/index.mjs'; import ind2sub from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ind2sub@esm/index.mjs'; -import maybeBroadcastArray from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-maybe-broadcast-array@esm/index.mjs'; +import maybeBroadcastArray from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-maybe-broadcast-array@v0.2.1-esm/index.mjs'; // Create a 2x2 array: var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); From 8a42a66aecabe2ed19739e83a6de45c75bb108d4 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 19:29:12 +0000 Subject: [PATCH 073/119] Auto-generated commit --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4493151..daa7771 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,11 @@ limitations under the License. ## Usage +```javascript +import maybeBroadcastArray from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-maybe-broadcast-array@esm/index.mjs'; +``` +The previous example will load the latest bundled code from the esm branch. Alternatively, you may load a specific version by loading the file from one of the [tagged bundles](https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tags). For example, + ```javascript import maybeBroadcastArray from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-maybe-broadcast-array@v0.2.1-esm/index.mjs'; ``` @@ -107,7 +112,7 @@ var y = maybeBroadcastArray( x, [ 2, 2, 2 ] ); import array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-array@esm/index.mjs'; import numel from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@esm/index.mjs'; import ind2sub from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ind2sub@esm/index.mjs'; -import maybeBroadcastArray from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-maybe-broadcast-array@v0.2.1-esm/index.mjs'; +import maybeBroadcastArray from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-maybe-broadcast-array@esm/index.mjs'; // Create a 2x2 array: var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); From 52afea8847b3d51f23753b5a88b3ccf54b4ee65d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Mar 2024 07:46:00 +0000 Subject: [PATCH 074/119] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 3250226..4980ec2 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,8 @@ "dependencies": { "@stdlib/ndarray-base-broadcast-array": "^0.2.1", "@stdlib/ndarray-base-shape": "^0.2.1", - "@stdlib/types": "^0.3.2" + "@stdlib/types": "^0.3.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1" }, "devDependencies": { "@stdlib/array-float64": "^0.2.1", @@ -90,4 +91,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From ca5ed72c71cd639e40d3344767d22dc23077d545 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Mar 2024 13:25:52 +0000 Subject: [PATCH 075/119] Remove files --- index.d.ts | 81 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4928 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 97640ae..0000000 --- a/index.d.ts +++ /dev/null @@ -1,81 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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'; -import { ndarray } from '@stdlib/types/ndarray'; - -/** -* Broadcasts an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* ## Notes -* -* - The function throws an error if a provided ndarray is incompatible with a provided shape. -* - If a provided ndarray has the same shape as the specified shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the specified shape, the function returns a new (base) ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to the view may affect multiple elements. If you need to write to the returned array, copy the array before performing operations which may mutate elements. -* - A returned array view is a "base" ndarray, and, thus, a returned array view does not perform bounds checking or afford any of the guarantees of the non-base ndarray constructor. The primary intent of this function is to broadcast an ndarray-like object within internal implementations and to do so with minimal overhead. -* -* @param arr - input array -* @param shape - desired shape -* @throws input array cannot have more dimensions than the desired shape -* @throws input array dimension sizes must be `1` or equal to the corresponding dimension in the provided shape -* @throws input array and desired shape must be broadcast compatible -* @returns broadcasted array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -*/ -declare function maybeBroadcastArray( arr: ndarray, shape: ArrayLike ): ndarray; - - -// EXPORTS // - -export = maybeBroadcastArray; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 9db3970..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@v0.2.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.0-esm/index.mjs";function e(e,s){var n,a,d;if(a=s.length,(n=t(e,!1)).length===a){for(d=0;d\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArray;\n"],"names":["maybeBroadcastArray","arr","shape","sh","N","i","length","getShape","broadcast"],"mappings":";;oMAqFA,SAASA,EAAqBC,EAAKC,GAClC,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAMI,QACVH,EAAKI,EAAUN,GAAK,IAGZK,SAAWF,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,KAAQH,EAAOG,GAEvB,OAAOG,EAAWP,EAAKC,GAGzB,OAAOD,CACP,CAED,OAAOO,EAAWP,EAAKC,EACxB"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index d5a7e7c..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 38b9396f9ba666cae7428b699f2a2e650e646c83 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Mar 2024 13:26:16 +0000 Subject: [PATCH 076/119] 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 | 49 +- SECURITY.md | 5 - benchmark/benchmark.js | 290 -- benchmark/benchmark.ndims.js | 110 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 68 - docs/types/test.ts | 94 - examples/index.js | 45 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 68 - lib/main.js | 112 - package.json | 64 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 514 --- 44 files changed, 4871 insertions(+), 4664 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/benchmark.ndims.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (97%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/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 223c193..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-03-01T05:36:24.746Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 740d5ce..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/maybe-broadcast-array) 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 4fadc31..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/maybe-broadcast-array) 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 31edc84..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: '45 9 * * 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 + + ```
@@ -173,7 +164,7 @@ for ( i = 0; i < N; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -236,11 +227,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-maybe-broadcast-array/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor +[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor/tree/esm -[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes +[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm
diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index ba5f734..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,290 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var ndarrayBase = require( '@stdlib/ndarray-base-ctor' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArray = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::base_ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::base_ndarray,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( out.shape[ 0 ] !== shape[ 0 ] ) { - b.fail( 'unexpected result' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.ndims.js b/benchmark/benchmark.ndims.js deleted file mode 100644 index 739b74c..0000000 --- a/benchmark/benchmark.ndims.js +++ /dev/null @@ -1,110 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var array = require( '@stdlib/ndarray-array' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} ndims - number of dimensions to which to broadcast -* @returns {Function} benchmark function -*/ -function createBenchmark( ndims ) { - var shape; - var sh; - var x; - var i; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - sh = x.shape; - - shape = []; - for ( i = 0; i < ndims; i++ ) { - shape.push( 0 ); - } - for ( i = ndims; i >= 1; i-- ) { - if ( i > sh.length ) { - shape[ ndims-i ] = 5; - } else { - shape[ ndims-i ] = sh[ i-1 ]; - } - } - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( x, shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var min; - var max; - var f; - var i; - - min = 2; - max = 10; - - for ( i = min; i <= max; i++ ) { - f = createBenchmark( i ); - bench( pkg+'::ndarray,2d:from_ndims=2,to_ndims='+i, f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index e45b5c4..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/maybe-broadcast-array" -%% click B href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/maybe-broadcast-array -[production-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 71859ce..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import maybeBroadcastArray from '../docs/types/index'; -export = maybeBroadcastArray; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 4b04e84..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var o=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var s=o(function(l,n){ -var u=require('@stdlib/ndarray-base-broadcast-array/dist'),v=require('@stdlib/ndarray-base-shape/dist');function c(e,r){var i,a,t;if(a=r.length,i=v(e,!1),i.length===a){for(t=0;t\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nmodule.exports = maybeBroadcastArray;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape.\n*\n* @module @stdlib/ndarray-base-maybe-broadcast-array\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var maybeBroadcastArray = require( '@stdlib/ndarray-base-maybe-broadcast-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAY,QAAS,sCAAuC,EAC5DC,EAAW,QAAS,4BAA6B,EA8DrD,SAASC,EAAqBC,EAAKC,EAAQ,CAC1C,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAM,OACVC,EAAKJ,EAAUE,EAAK,EAAM,EAGrBE,EAAG,SAAWC,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,CAAE,IAAMH,EAAOG,CAAE,EAEzB,OAAOP,EAAWG,EAAKC,CAAM,EAG/B,OAAOD,CACR,CAEA,OAAOH,EAAWG,EAAKC,CAAM,CAC9B,CAKAL,EAAO,QAAUG,ICjDjB,IAAIM,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "broadcast", "getShape", "maybeBroadcastArray", "arr", "shape", "sh", "N", "i", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 01ecba8..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,68 +0,0 @@ - -{{alias}}( arr, shape ) - Broadcasts an ndarray to a specified shape if and only if the specified - shape differs from the provided ndarray's shape. - - If a provided ndarray has the same shape as the specified shape, the - function returns the provided ndarray. - - If a provided ndarray has a different (broadcast compatible) shape than the - specified shape, the function returns a new (base) ndarray view of the - provided ndarray's data. The view is typically **not** contiguous. As more - than one element of a returned view may refer to the same memory location, - writing to the view may affect multiple elements. If you need to write to - the returned array, copy the array before performing operations which may - mutate elements. - - A returned array view is a "base" ndarray, and, thus, a returned array view - does not perform bounds checking or afford any of the guarantees of the non- - base ndarray constructor. The primary intent of this function is to - broadcast an ndarray-like object within internal implementations and to do - so with minimal overhead. - - The function throws an error if a provided ndarray is incompatible with a - provided shape. - - Parameters - ---------- - arr: ndarray - Input array. - - shape: ArrayLikeObject - Desired shape. - - Returns - ------- - out: ndarray - Broadcasted array. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > var sh = x.shape - [ 2, 2 ] - > var y = {{alias}}( x, [ 3, 2, 2 ] ) - - > sh = y.shape - [ 3, 2, 2 ] - > var v = y.get( 0, 0, 0 ) - 1 - > v = y.get( 0, 0, 1 ) - 2 - > v = y.get( 0, 1, 0 ) - 3 - > v = y.get( 0, 1, 1 ) - 4 - > v = y.get( 1, 0, 0 ) - 1 - > v = y.get( 1, 1, 0 ) - 3 - > v = y.get( 2, 0, 0 ) - 1 - > v = y.get( 2, 1, 1 ) - 4 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index d7a1a62..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,94 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ndarray } from '@stdlib/types/ndarray'; -import maybeBroadcastArray = require( './index' ); - -/** -* Mock function to create an ndarray-like object. -* -* @return ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns an ndarray... -{ - const x = array(); - - maybeBroadcastArray( x, [ 2, 2, 2 ] ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is not provided a first argument which is an ndarray... -{ - maybeBroadcastArray( '5', [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( 5, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( true, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( false, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( null, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( {}, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( [ '5' ], [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( ( x: number ): number => x, [ 2, 2, 2 ] ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a second argument which is an array-like object containing numbers... -{ - const x = array(); - - maybeBroadcastArray( x, '5' ); // $ExpectError - maybeBroadcastArray( x, 5 ); // $ExpectError - maybeBroadcastArray( x, true ); // $ExpectError - maybeBroadcastArray( x, false ); // $ExpectError - maybeBroadcastArray( x, null ); // $ExpectError - maybeBroadcastArray( x, {} ); // $ExpectError - maybeBroadcastArray( x, [ '5' ] ); // $ExpectError - maybeBroadcastArray( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - - maybeBroadcastArray(); // $ExpectError - maybeBroadcastArray( x ); // $ExpectError - maybeBroadcastArray( x, [ 1, 2, 3 ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index e787d6e..0000000 --- a/examples/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 array = require( '@stdlib/ndarray-array' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var maybeBroadcastArray = require( './../lib' ); - -// Create a 2x2 array: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -// returns - -// Broadcast the array to 3x2x2: -var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -// returns - -// Retrieve the shape: -var sh = y.shape; -// returns [ 3, 2, 2 ] - -// Retrieve the number of elements: -var N = numel( sh ); - -// Loop through the array elements... -var i; -for ( i = 0; i < N; i++ ) { - console.log( 'Y[%s] = %d', ind2sub( sh, i ).join( ', ' ), y.iget( i ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 97% rename from docs/types/index.d.ts rename to index.d.ts index f354818..97640ae 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..47264a6 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.1-esm/index.mjs";function e(e,s){var n,a,d;if(a=s.length,(n=t(e,!1)).length===a){for(d=0;d\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArray;\n"],"names":["maybeBroadcastArray","arr","shape","sh","N","i","length","getShape","broadcast"],"mappings":";;oMAqFA,SAASA,EAAqBC,EAAKC,GAClC,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAMI,QACVH,EAAKI,EAAUN,GAAK,IAGZK,SAAWF,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,KAAQH,EAAOG,GAEvB,OAAOG,EAAWP,EAAKC,GAGzB,OAAOD,CACP,CAED,OAAOO,EAAWP,EAAKC,EACxB"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 834e930..0000000 --- a/lib/index.js +++ /dev/null @@ -1,68 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* @module @stdlib/ndarray-base-maybe-broadcast-array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var maybeBroadcastArray = require( '@stdlib/ndarray-base-maybe-broadcast-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -*/ - -// 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 e59ca1d..0000000 --- a/lib/main.js +++ /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. -*/ - -'use strict'; - -// MODULES // - -var broadcast = require( '@stdlib/ndarray-base-broadcast-array' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); - - -// MAIN // - -/** -* Broadcasts an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* ## Notes -* -* - If a provided ndarray has the same shape as the specified shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the specified shape, the function returns a new (base) ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to the view may affect multiple elements. If you need to write to the returned array, copy the array before performing operations which may mutate elements. -* -* @param {ndarray} arr - input array -* @param {NonNegativeIntegerArray} shape - desired shape -* @throws {Error} input array cannot have more dimensions than the desired shape -* @throws {Error} input array dimension sizes must be `1` or equal to the corresponding dimension in the provided shape -* @throws {Error} input array and desired shape must be broadcast compatible -* @returns {ndarray} broadcasted array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var y = maybeBroadcastArray( x, [ 3, 2 ] ); -* // throws -*/ -function maybeBroadcastArray( arr, shape ) { - var sh; - var N; - var i; - - N = shape.length; - sh = getShape( arr, false ); - - // Check whether we need to broadcast the input array... - if ( sh.length === N ) { - for ( i = 0; i < N; i++ ) { - // Check whether dimensions match... - if ( sh[ i ] !== shape[ i ] ) { - // We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape... - return broadcast( arr, shape ); - } - } - return arr; - } - // If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape... - return broadcast( arr, shape ); -} - - -// EXPORTS // - -module.exports = maybeBroadcastArray; diff --git a/package.json b/package.json index 4980ec2..823b56b 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Broadcast an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's 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", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-base-broadcast-array": "^0.2.1", - "@stdlib/ndarray-base-shape": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.2.1", - "@stdlib/assert-is-ndarray-like": "^0.2.1", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-base-ctor": "^0.2.1", - "@stdlib/ndarray-base-numel": "^0.2.1", - "@stdlib/ndarray-ctor": "^0.2.1", - "@stdlib/ndarray-ind2sub": "^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", @@ -86,9 +29,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..d02ab5b --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 7e8e63f..0000000 --- a/test/test.js +++ /dev/null @@ -1,514 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 array = require( '@stdlib/ndarray-array' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var maybeBroadcastArray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof maybeBroadcastArray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a desired shape which has fewer dimensions than the input array', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 ] - }); - - values = [ - [], - [ 2 ], - [ 2, 2 ], - [ 2, 2, 2 ], - [ 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2, 2, 2 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided a shape with '+values[ i ].length+' dimension' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape having a dimension whose size is less than the corresponding dimension in the input array', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 10, 1 ], - [ 10, 10, 2 ], - [ 10, 10, 9 ], - [ 10, 1, 10 ], - [ 10, 2, 10 ], - [ 10, 9, 10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape and an input array shape which are broadcast-incompatible', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 20, 10 ], - [ 10, 10, 100 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function returns a "base" ndarray instance', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = maybeBroadcastArray( x, [ 2, 2, 2 ] ); - - t.notEqual( y, x, 'returns new instance' ); - t.strictEqual( y instanceof ndarray, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view over the input array data buffer', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = maybeBroadcastArray( x, [ 2, 2, 2 ] ); - - t.strictEqual( y.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; strides)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, -1 ], 3, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; strides)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, 1 ], 2, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; non-contiguous)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ 4, 2 ], 1, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 5 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 7 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (column-major)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'column-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (same shape)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2, 2 ], - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - // Should return the same instance: - t.strictEqual( y, x, 'returns expected value' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 1, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 1, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (same number of dimensions)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1, 2 ], - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (singleton dimension)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (singleton dimension)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 1, 2 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (0-dimensional array)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1 ]; - x = ndarray( 'generic', data, [], [ 0 ], 0, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); From 4af83d3e9b1fdfddf8a20ed4cb971763069ae3e5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 07:04:35 +0000 Subject: [PATCH 077/119] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 3250226..4980ec2 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,8 @@ "dependencies": { "@stdlib/ndarray-base-broadcast-array": "^0.2.1", "@stdlib/ndarray-base-shape": "^0.2.1", - "@stdlib/types": "^0.3.2" + "@stdlib/types": "^0.3.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1" }, "devDependencies": { "@stdlib/array-float64": "^0.2.1", @@ -90,4 +91,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From 4b1c8cccc37709778a2d71d6eeb4bb9a9251ab87 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 12:20:59 +0000 Subject: [PATCH 078/119] Remove files --- index.d.ts | 81 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4928 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 97640ae..0000000 --- a/index.d.ts +++ /dev/null @@ -1,81 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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'; -import { ndarray } from '@stdlib/types/ndarray'; - -/** -* Broadcasts an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* ## Notes -* -* - The function throws an error if a provided ndarray is incompatible with a provided shape. -* - If a provided ndarray has the same shape as the specified shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the specified shape, the function returns a new (base) ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to the view may affect multiple elements. If you need to write to the returned array, copy the array before performing operations which may mutate elements. -* - A returned array view is a "base" ndarray, and, thus, a returned array view does not perform bounds checking or afford any of the guarantees of the non-base ndarray constructor. The primary intent of this function is to broadcast an ndarray-like object within internal implementations and to do so with minimal overhead. -* -* @param arr - input array -* @param shape - desired shape -* @throws input array cannot have more dimensions than the desired shape -* @throws input array dimension sizes must be `1` or equal to the corresponding dimension in the provided shape -* @throws input array and desired shape must be broadcast compatible -* @returns broadcasted array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -*/ -declare function maybeBroadcastArray( arr: ndarray, shape: ArrayLike ): ndarray; - - -// EXPORTS // - -export = maybeBroadcastArray; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 47264a6..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.1-esm/index.mjs";function e(e,s){var n,a,d;if(a=s.length,(n=t(e,!1)).length===a){for(d=0;d\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArray;\n"],"names":["maybeBroadcastArray","arr","shape","sh","N","i","length","getShape","broadcast"],"mappings":";;oMAqFA,SAASA,EAAqBC,EAAKC,GAClC,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAMI,QACVH,EAAKI,EAAUN,GAAK,IAGZK,SAAWF,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,KAAQH,EAAOG,GAEvB,OAAOG,EAAWP,EAAKC,GAGzB,OAAOD,CACP,CAED,OAAOO,EAAWP,EAAKC,EACxB"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index d02ab5b..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 0311eb19512be5dd104dc7bb7bd3702127c0e1e7 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 12:21:13 +0000 Subject: [PATCH 079/119] 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 | 49 +- SECURITY.md | 5 - benchmark/benchmark.js | 290 -- benchmark/benchmark.ndims.js | 110 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 68 - docs/types/test.ts | 94 - examples/index.js | 45 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 68 - lib/main.js | 112 - package.json | 64 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 514 --- 44 files changed, 4871 insertions(+), 4667 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/benchmark.ndims.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (97%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/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 098c302..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-04-01T04:55:13.102Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 740d5ce..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/maybe-broadcast-array) 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 4fadc31..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/maybe-broadcast-array) 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 31edc84..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: '45 9 * * 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 + + ```
@@ -173,7 +164,7 @@ for ( i = 0; i < N; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -236,11 +227,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-maybe-broadcast-array/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor +[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor/tree/esm -[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes +[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm
diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index ba5f734..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,290 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var ndarrayBase = require( '@stdlib/ndarray-base-ctor' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArray = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::base_ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::base_ndarray,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( out.shape[ 0 ] !== shape[ 0 ] ) { - b.fail( 'unexpected result' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.ndims.js b/benchmark/benchmark.ndims.js deleted file mode 100644 index 739b74c..0000000 --- a/benchmark/benchmark.ndims.js +++ /dev/null @@ -1,110 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var array = require( '@stdlib/ndarray-array' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} ndims - number of dimensions to which to broadcast -* @returns {Function} benchmark function -*/ -function createBenchmark( ndims ) { - var shape; - var sh; - var x; - var i; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - sh = x.shape; - - shape = []; - for ( i = 0; i < ndims; i++ ) { - shape.push( 0 ); - } - for ( i = ndims; i >= 1; i-- ) { - if ( i > sh.length ) { - shape[ ndims-i ] = 5; - } else { - shape[ ndims-i ] = sh[ i-1 ]; - } - } - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( x, shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var min; - var max; - var f; - var i; - - min = 2; - max = 10; - - for ( i = min; i <= max; i++ ) { - f = createBenchmark( i ); - bench( pkg+'::ndarray,2d:from_ndims=2,to_ndims='+i, f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index e45b5c4..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/maybe-broadcast-array" -%% click B href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/maybe-broadcast-array -[production-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 71859ce..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import maybeBroadcastArray from '../docs/types/index'; -export = maybeBroadcastArray; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 4b04e84..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var o=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var s=o(function(l,n){ -var u=require('@stdlib/ndarray-base-broadcast-array/dist'),v=require('@stdlib/ndarray-base-shape/dist');function c(e,r){var i,a,t;if(a=r.length,i=v(e,!1),i.length===a){for(t=0;t\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nmodule.exports = maybeBroadcastArray;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape.\n*\n* @module @stdlib/ndarray-base-maybe-broadcast-array\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var maybeBroadcastArray = require( '@stdlib/ndarray-base-maybe-broadcast-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAY,QAAS,sCAAuC,EAC5DC,EAAW,QAAS,4BAA6B,EA8DrD,SAASC,EAAqBC,EAAKC,EAAQ,CAC1C,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAM,OACVC,EAAKJ,EAAUE,EAAK,EAAM,EAGrBE,EAAG,SAAWC,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,CAAE,IAAMH,EAAOG,CAAE,EAEzB,OAAOP,EAAWG,EAAKC,CAAM,EAG/B,OAAOD,CACR,CAEA,OAAOH,EAAWG,EAAKC,CAAM,CAC9B,CAKAL,EAAO,QAAUG,ICjDjB,IAAIM,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "broadcast", "getShape", "maybeBroadcastArray", "arr", "shape", "sh", "N", "i", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 01ecba8..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,68 +0,0 @@ - -{{alias}}( arr, shape ) - Broadcasts an ndarray to a specified shape if and only if the specified - shape differs from the provided ndarray's shape. - - If a provided ndarray has the same shape as the specified shape, the - function returns the provided ndarray. - - If a provided ndarray has a different (broadcast compatible) shape than the - specified shape, the function returns a new (base) ndarray view of the - provided ndarray's data. The view is typically **not** contiguous. As more - than one element of a returned view may refer to the same memory location, - writing to the view may affect multiple elements. If you need to write to - the returned array, copy the array before performing operations which may - mutate elements. - - A returned array view is a "base" ndarray, and, thus, a returned array view - does not perform bounds checking or afford any of the guarantees of the non- - base ndarray constructor. The primary intent of this function is to - broadcast an ndarray-like object within internal implementations and to do - so with minimal overhead. - - The function throws an error if a provided ndarray is incompatible with a - provided shape. - - Parameters - ---------- - arr: ndarray - Input array. - - shape: ArrayLikeObject - Desired shape. - - Returns - ------- - out: ndarray - Broadcasted array. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > var sh = x.shape - [ 2, 2 ] - > var y = {{alias}}( x, [ 3, 2, 2 ] ) - - > sh = y.shape - [ 3, 2, 2 ] - > var v = y.get( 0, 0, 0 ) - 1 - > v = y.get( 0, 0, 1 ) - 2 - > v = y.get( 0, 1, 0 ) - 3 - > v = y.get( 0, 1, 1 ) - 4 - > v = y.get( 1, 0, 0 ) - 1 - > v = y.get( 1, 1, 0 ) - 3 - > v = y.get( 2, 0, 0 ) - 1 - > v = y.get( 2, 1, 1 ) - 4 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index d7a1a62..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,94 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ndarray } from '@stdlib/types/ndarray'; -import maybeBroadcastArray = require( './index' ); - -/** -* Mock function to create an ndarray-like object. -* -* @return ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns an ndarray... -{ - const x = array(); - - maybeBroadcastArray( x, [ 2, 2, 2 ] ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is not provided a first argument which is an ndarray... -{ - maybeBroadcastArray( '5', [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( 5, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( true, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( false, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( null, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( {}, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( [ '5' ], [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( ( x: number ): number => x, [ 2, 2, 2 ] ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a second argument which is an array-like object containing numbers... -{ - const x = array(); - - maybeBroadcastArray( x, '5' ); // $ExpectError - maybeBroadcastArray( x, 5 ); // $ExpectError - maybeBroadcastArray( x, true ); // $ExpectError - maybeBroadcastArray( x, false ); // $ExpectError - maybeBroadcastArray( x, null ); // $ExpectError - maybeBroadcastArray( x, {} ); // $ExpectError - maybeBroadcastArray( x, [ '5' ] ); // $ExpectError - maybeBroadcastArray( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - - maybeBroadcastArray(); // $ExpectError - maybeBroadcastArray( x ); // $ExpectError - maybeBroadcastArray( x, [ 1, 2, 3 ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index e787d6e..0000000 --- a/examples/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 array = require( '@stdlib/ndarray-array' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var maybeBroadcastArray = require( './../lib' ); - -// Create a 2x2 array: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -// returns - -// Broadcast the array to 3x2x2: -var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -// returns - -// Retrieve the shape: -var sh = y.shape; -// returns [ 3, 2, 2 ] - -// Retrieve the number of elements: -var N = numel( sh ); - -// Loop through the array elements... -var i; -for ( i = 0; i < N; i++ ) { - console.log( 'Y[%s] = %d', ind2sub( sh, i ).join( ', ' ), y.iget( i ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 97% rename from docs/types/index.d.ts rename to index.d.ts index f354818..97640ae 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..47264a6 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.1-esm/index.mjs";function e(e,s){var n,a,d;if(a=s.length,(n=t(e,!1)).length===a){for(d=0;d\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArray;\n"],"names":["maybeBroadcastArray","arr","shape","sh","N","i","length","getShape","broadcast"],"mappings":";;oMAqFA,SAASA,EAAqBC,EAAKC,GAClC,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAMI,QACVH,EAAKI,EAAUN,GAAK,IAGZK,SAAWF,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,KAAQH,EAAOG,GAEvB,OAAOG,EAAWP,EAAKC,GAGzB,OAAOD,CACP,CAED,OAAOO,EAAWP,EAAKC,EACxB"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 834e930..0000000 --- a/lib/index.js +++ /dev/null @@ -1,68 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* @module @stdlib/ndarray-base-maybe-broadcast-array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var maybeBroadcastArray = require( '@stdlib/ndarray-base-maybe-broadcast-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -*/ - -// 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 e59ca1d..0000000 --- a/lib/main.js +++ /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. -*/ - -'use strict'; - -// MODULES // - -var broadcast = require( '@stdlib/ndarray-base-broadcast-array' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); - - -// MAIN // - -/** -* Broadcasts an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* ## Notes -* -* - If a provided ndarray has the same shape as the specified shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the specified shape, the function returns a new (base) ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to the view may affect multiple elements. If you need to write to the returned array, copy the array before performing operations which may mutate elements. -* -* @param {ndarray} arr - input array -* @param {NonNegativeIntegerArray} shape - desired shape -* @throws {Error} input array cannot have more dimensions than the desired shape -* @throws {Error} input array dimension sizes must be `1` or equal to the corresponding dimension in the provided shape -* @throws {Error} input array and desired shape must be broadcast compatible -* @returns {ndarray} broadcasted array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var y = maybeBroadcastArray( x, [ 3, 2 ] ); -* // throws -*/ -function maybeBroadcastArray( arr, shape ) { - var sh; - var N; - var i; - - N = shape.length; - sh = getShape( arr, false ); - - // Check whether we need to broadcast the input array... - if ( sh.length === N ) { - for ( i = 0; i < N; i++ ) { - // Check whether dimensions match... - if ( sh[ i ] !== shape[ i ] ) { - // We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape... - return broadcast( arr, shape ); - } - } - return arr; - } - // If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape... - return broadcast( arr, shape ); -} - - -// EXPORTS // - -module.exports = maybeBroadcastArray; diff --git a/package.json b/package.json index 4980ec2..823b56b 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Broadcast an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's 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", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-base-broadcast-array": "^0.2.1", - "@stdlib/ndarray-base-shape": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.2.1", - "@stdlib/assert-is-ndarray-like": "^0.2.1", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-base-ctor": "^0.2.1", - "@stdlib/ndarray-base-numel": "^0.2.1", - "@stdlib/ndarray-ctor": "^0.2.1", - "@stdlib/ndarray-ind2sub": "^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", @@ -86,9 +29,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..d02ab5b --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 7e8e63f..0000000 --- a/test/test.js +++ /dev/null @@ -1,514 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 array = require( '@stdlib/ndarray-array' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var maybeBroadcastArray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof maybeBroadcastArray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a desired shape which has fewer dimensions than the input array', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 ] - }); - - values = [ - [], - [ 2 ], - [ 2, 2 ], - [ 2, 2, 2 ], - [ 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2, 2, 2 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided a shape with '+values[ i ].length+' dimension' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape having a dimension whose size is less than the corresponding dimension in the input array', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 10, 1 ], - [ 10, 10, 2 ], - [ 10, 10, 9 ], - [ 10, 1, 10 ], - [ 10, 2, 10 ], - [ 10, 9, 10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape and an input array shape which are broadcast-incompatible', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 20, 10 ], - [ 10, 10, 100 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function returns a "base" ndarray instance', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = maybeBroadcastArray( x, [ 2, 2, 2 ] ); - - t.notEqual( y, x, 'returns new instance' ); - t.strictEqual( y instanceof ndarray, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view over the input array data buffer', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = maybeBroadcastArray( x, [ 2, 2, 2 ] ); - - t.strictEqual( y.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; strides)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, -1 ], 3, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; strides)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, 1 ], 2, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; non-contiguous)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ 4, 2 ], 1, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 5 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 7 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (column-major)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'column-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (same shape)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2, 2 ], - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - // Should return the same instance: - t.strictEqual( y, x, 'returns expected value' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 1, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 1, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (same number of dimensions)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1, 2 ], - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (singleton dimension)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (singleton dimension)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 1, 2 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (0-dimensional array)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1 ]; - x = ndarray( 'generic', data, [], [ 0 ], 0, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); From f5ec11ec2c88bdd011d2a46aaa5a61d90b3ec3e3 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 12 Apr 2024 03:20:56 +0000 Subject: [PATCH 080/119] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 3250226..4980ec2 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,8 @@ "dependencies": { "@stdlib/ndarray-base-broadcast-array": "^0.2.1", "@stdlib/ndarray-base-shape": "^0.2.1", - "@stdlib/types": "^0.3.2" + "@stdlib/types": "^0.3.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1" }, "devDependencies": { "@stdlib/array-float64": "^0.2.1", @@ -90,4 +91,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From aefc03d35ffeb0deeb38b04543f9036036f1d374 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 12 Apr 2024 08:42:48 +0000 Subject: [PATCH 081/119] Remove files --- index.d.ts | 81 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4928 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 97640ae..0000000 --- a/index.d.ts +++ /dev/null @@ -1,81 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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'; -import { ndarray } from '@stdlib/types/ndarray'; - -/** -* Broadcasts an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* ## Notes -* -* - The function throws an error if a provided ndarray is incompatible with a provided shape. -* - If a provided ndarray has the same shape as the specified shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the specified shape, the function returns a new (base) ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to the view may affect multiple elements. If you need to write to the returned array, copy the array before performing operations which may mutate elements. -* - A returned array view is a "base" ndarray, and, thus, a returned array view does not perform bounds checking or afford any of the guarantees of the non-base ndarray constructor. The primary intent of this function is to broadcast an ndarray-like object within internal implementations and to do so with minimal overhead. -* -* @param arr - input array -* @param shape - desired shape -* @throws input array cannot have more dimensions than the desired shape -* @throws input array dimension sizes must be `1` or equal to the corresponding dimension in the provided shape -* @throws input array and desired shape must be broadcast compatible -* @returns broadcasted array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -*/ -declare function maybeBroadcastArray( arr: ndarray, shape: ArrayLike ): ndarray; - - -// EXPORTS // - -export = maybeBroadcastArray; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 47264a6..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.1-esm/index.mjs";function e(e,s){var n,a,d;if(a=s.length,(n=t(e,!1)).length===a){for(d=0;d\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArray;\n"],"names":["maybeBroadcastArray","arr","shape","sh","N","i","length","getShape","broadcast"],"mappings":";;oMAqFA,SAASA,EAAqBC,EAAKC,GAClC,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAMI,QACVH,EAAKI,EAAUN,GAAK,IAGZK,SAAWF,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,KAAQH,EAAOG,GAEvB,OAAOG,EAAWP,EAAKC,GAGzB,OAAOD,CACP,CAED,OAAOO,EAAWP,EAAKC,EACxB"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index d02ab5b..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From a3a96bbb7429afb937f1db3179f5615564aaf6e8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 12 Apr 2024 08:43:04 +0000 Subject: [PATCH 082/119] 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 | 49 +- SECURITY.md | 5 - benchmark/benchmark.js | 290 -- benchmark/benchmark.ndims.js | 110 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 68 - docs/types/test.ts | 94 - examples/index.js | 45 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 68 - lib/main.js | 112 - package.json | 64 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 514 --- 43 files changed, 4871 insertions(+), 4668 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/benchmark.ndims.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (97%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/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 740d5ce..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/maybe-broadcast-array) 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 4fadc31..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/maybe-broadcast-array) 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 31edc84..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: '45 9 * * 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 + + ```
@@ -173,7 +164,7 @@ for ( i = 0; i < N; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -236,11 +227,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-maybe-broadcast-array/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor +[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor/tree/esm -[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes +[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm
diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index ba5f734..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,290 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var ndarrayBase = require( '@stdlib/ndarray-base-ctor' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArray = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::base_ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::base_ndarray,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( out.shape[ 0 ] !== shape[ 0 ] ) { - b.fail( 'unexpected result' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.ndims.js b/benchmark/benchmark.ndims.js deleted file mode 100644 index 739b74c..0000000 --- a/benchmark/benchmark.ndims.js +++ /dev/null @@ -1,110 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var array = require( '@stdlib/ndarray-array' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} ndims - number of dimensions to which to broadcast -* @returns {Function} benchmark function -*/ -function createBenchmark( ndims ) { - var shape; - var sh; - var x; - var i; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - sh = x.shape; - - shape = []; - for ( i = 0; i < ndims; i++ ) { - shape.push( 0 ); - } - for ( i = ndims; i >= 1; i-- ) { - if ( i > sh.length ) { - shape[ ndims-i ] = 5; - } else { - shape[ ndims-i ] = sh[ i-1 ]; - } - } - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( x, shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var min; - var max; - var f; - var i; - - min = 2; - max = 10; - - for ( i = min; i <= max; i++ ) { - f = createBenchmark( i ); - bench( pkg+'::ndarray,2d:from_ndims=2,to_ndims='+i, f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index e45b5c4..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/maybe-broadcast-array" -%% click B href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/maybe-broadcast-array -[production-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 71859ce..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import maybeBroadcastArray from '../docs/types/index'; -export = maybeBroadcastArray; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 4b04e84..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var o=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var s=o(function(l,n){ -var u=require('@stdlib/ndarray-base-broadcast-array/dist'),v=require('@stdlib/ndarray-base-shape/dist');function c(e,r){var i,a,t;if(a=r.length,i=v(e,!1),i.length===a){for(t=0;t\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nmodule.exports = maybeBroadcastArray;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape.\n*\n* @module @stdlib/ndarray-base-maybe-broadcast-array\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var maybeBroadcastArray = require( '@stdlib/ndarray-base-maybe-broadcast-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAY,QAAS,sCAAuC,EAC5DC,EAAW,QAAS,4BAA6B,EA8DrD,SAASC,EAAqBC,EAAKC,EAAQ,CAC1C,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAM,OACVC,EAAKJ,EAAUE,EAAK,EAAM,EAGrBE,EAAG,SAAWC,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,CAAE,IAAMH,EAAOG,CAAE,EAEzB,OAAOP,EAAWG,EAAKC,CAAM,EAG/B,OAAOD,CACR,CAEA,OAAOH,EAAWG,EAAKC,CAAM,CAC9B,CAKAL,EAAO,QAAUG,ICjDjB,IAAIM,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "broadcast", "getShape", "maybeBroadcastArray", "arr", "shape", "sh", "N", "i", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 01ecba8..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,68 +0,0 @@ - -{{alias}}( arr, shape ) - Broadcasts an ndarray to a specified shape if and only if the specified - shape differs from the provided ndarray's shape. - - If a provided ndarray has the same shape as the specified shape, the - function returns the provided ndarray. - - If a provided ndarray has a different (broadcast compatible) shape than the - specified shape, the function returns a new (base) ndarray view of the - provided ndarray's data. The view is typically **not** contiguous. As more - than one element of a returned view may refer to the same memory location, - writing to the view may affect multiple elements. If you need to write to - the returned array, copy the array before performing operations which may - mutate elements. - - A returned array view is a "base" ndarray, and, thus, a returned array view - does not perform bounds checking or afford any of the guarantees of the non- - base ndarray constructor. The primary intent of this function is to - broadcast an ndarray-like object within internal implementations and to do - so with minimal overhead. - - The function throws an error if a provided ndarray is incompatible with a - provided shape. - - Parameters - ---------- - arr: ndarray - Input array. - - shape: ArrayLikeObject - Desired shape. - - Returns - ------- - out: ndarray - Broadcasted array. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > var sh = x.shape - [ 2, 2 ] - > var y = {{alias}}( x, [ 3, 2, 2 ] ) - - > sh = y.shape - [ 3, 2, 2 ] - > var v = y.get( 0, 0, 0 ) - 1 - > v = y.get( 0, 0, 1 ) - 2 - > v = y.get( 0, 1, 0 ) - 3 - > v = y.get( 0, 1, 1 ) - 4 - > v = y.get( 1, 0, 0 ) - 1 - > v = y.get( 1, 1, 0 ) - 3 - > v = y.get( 2, 0, 0 ) - 1 - > v = y.get( 2, 1, 1 ) - 4 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index d7a1a62..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,94 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ndarray } from '@stdlib/types/ndarray'; -import maybeBroadcastArray = require( './index' ); - -/** -* Mock function to create an ndarray-like object. -* -* @return ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns an ndarray... -{ - const x = array(); - - maybeBroadcastArray( x, [ 2, 2, 2 ] ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is not provided a first argument which is an ndarray... -{ - maybeBroadcastArray( '5', [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( 5, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( true, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( false, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( null, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( {}, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( [ '5' ], [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( ( x: number ): number => x, [ 2, 2, 2 ] ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a second argument which is an array-like object containing numbers... -{ - const x = array(); - - maybeBroadcastArray( x, '5' ); // $ExpectError - maybeBroadcastArray( x, 5 ); // $ExpectError - maybeBroadcastArray( x, true ); // $ExpectError - maybeBroadcastArray( x, false ); // $ExpectError - maybeBroadcastArray( x, null ); // $ExpectError - maybeBroadcastArray( x, {} ); // $ExpectError - maybeBroadcastArray( x, [ '5' ] ); // $ExpectError - maybeBroadcastArray( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - - maybeBroadcastArray(); // $ExpectError - maybeBroadcastArray( x ); // $ExpectError - maybeBroadcastArray( x, [ 1, 2, 3 ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index e787d6e..0000000 --- a/examples/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 array = require( '@stdlib/ndarray-array' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var maybeBroadcastArray = require( './../lib' ); - -// Create a 2x2 array: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -// returns - -// Broadcast the array to 3x2x2: -var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -// returns - -// Retrieve the shape: -var sh = y.shape; -// returns [ 3, 2, 2 ] - -// Retrieve the number of elements: -var N = numel( sh ); - -// Loop through the array elements... -var i; -for ( i = 0; i < N; i++ ) { - console.log( 'Y[%s] = %d', ind2sub( sh, i ).join( ', ' ), y.iget( i ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 97% rename from docs/types/index.d.ts rename to index.d.ts index f354818..97640ae 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..47264a6 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.1-esm/index.mjs";function e(e,s){var n,a,d;if(a=s.length,(n=t(e,!1)).length===a){for(d=0;d\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArray;\n"],"names":["maybeBroadcastArray","arr","shape","sh","N","i","length","getShape","broadcast"],"mappings":";;oMAqFA,SAASA,EAAqBC,EAAKC,GAClC,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAMI,QACVH,EAAKI,EAAUN,GAAK,IAGZK,SAAWF,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,KAAQH,EAAOG,GAEvB,OAAOG,EAAWP,EAAKC,GAGzB,OAAOD,CACP,CAED,OAAOO,EAAWP,EAAKC,EACxB"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 834e930..0000000 --- a/lib/index.js +++ /dev/null @@ -1,68 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* @module @stdlib/ndarray-base-maybe-broadcast-array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var maybeBroadcastArray = require( '@stdlib/ndarray-base-maybe-broadcast-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -*/ - -// 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 e59ca1d..0000000 --- a/lib/main.js +++ /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. -*/ - -'use strict'; - -// MODULES // - -var broadcast = require( '@stdlib/ndarray-base-broadcast-array' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); - - -// MAIN // - -/** -* Broadcasts an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* ## Notes -* -* - If a provided ndarray has the same shape as the specified shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the specified shape, the function returns a new (base) ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to the view may affect multiple elements. If you need to write to the returned array, copy the array before performing operations which may mutate elements. -* -* @param {ndarray} arr - input array -* @param {NonNegativeIntegerArray} shape - desired shape -* @throws {Error} input array cannot have more dimensions than the desired shape -* @throws {Error} input array dimension sizes must be `1` or equal to the corresponding dimension in the provided shape -* @throws {Error} input array and desired shape must be broadcast compatible -* @returns {ndarray} broadcasted array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var y = maybeBroadcastArray( x, [ 3, 2 ] ); -* // throws -*/ -function maybeBroadcastArray( arr, shape ) { - var sh; - var N; - var i; - - N = shape.length; - sh = getShape( arr, false ); - - // Check whether we need to broadcast the input array... - if ( sh.length === N ) { - for ( i = 0; i < N; i++ ) { - // Check whether dimensions match... - if ( sh[ i ] !== shape[ i ] ) { - // We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape... - return broadcast( arr, shape ); - } - } - return arr; - } - // If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape... - return broadcast( arr, shape ); -} - - -// EXPORTS // - -module.exports = maybeBroadcastArray; diff --git a/package.json b/package.json index 4980ec2..823b56b 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Broadcast an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's 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", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-base-broadcast-array": "^0.2.1", - "@stdlib/ndarray-base-shape": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.2.1", - "@stdlib/assert-is-ndarray-like": "^0.2.1", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-base-ctor": "^0.2.1", - "@stdlib/ndarray-base-numel": "^0.2.1", - "@stdlib/ndarray-ctor": "^0.2.1", - "@stdlib/ndarray-ind2sub": "^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", @@ -86,9 +29,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..d02ab5b --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 7e8e63f..0000000 --- a/test/test.js +++ /dev/null @@ -1,514 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 array = require( '@stdlib/ndarray-array' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var maybeBroadcastArray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof maybeBroadcastArray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a desired shape which has fewer dimensions than the input array', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 ] - }); - - values = [ - [], - [ 2 ], - [ 2, 2 ], - [ 2, 2, 2 ], - [ 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2, 2, 2 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided a shape with '+values[ i ].length+' dimension' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape having a dimension whose size is less than the corresponding dimension in the input array', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 10, 1 ], - [ 10, 10, 2 ], - [ 10, 10, 9 ], - [ 10, 1, 10 ], - [ 10, 2, 10 ], - [ 10, 9, 10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape and an input array shape which are broadcast-incompatible', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 20, 10 ], - [ 10, 10, 100 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function returns a "base" ndarray instance', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = maybeBroadcastArray( x, [ 2, 2, 2 ] ); - - t.notEqual( y, x, 'returns new instance' ); - t.strictEqual( y instanceof ndarray, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view over the input array data buffer', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = maybeBroadcastArray( x, [ 2, 2, 2 ] ); - - t.strictEqual( y.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; strides)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, -1 ], 3, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; strides)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, 1 ], 2, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; non-contiguous)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ 4, 2 ], 1, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 5 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 7 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (column-major)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'column-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (same shape)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2, 2 ], - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - // Should return the same instance: - t.strictEqual( y, x, 'returns expected value' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 1, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 1, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (same number of dimensions)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1, 2 ], - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (singleton dimension)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (singleton dimension)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 1, 2 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (0-dimensional array)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1 ]; - x = ndarray( 'generic', data, [], [ 0 ], 0, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); From e9da639b75a6e15b6dd1e2032de9ee0ffec32840 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 29 Jul 2024 02:23:57 +0000 Subject: [PATCH 083/119] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index fe03ac4..f26e17b 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,8 @@ "dependencies": { "@stdlib/ndarray-base-broadcast-array": "^0.2.1", "@stdlib/ndarray-base-shape": "^0.2.1", - "@stdlib/types": "^0.3.2" + "@stdlib/types": "^0.3.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, "devDependencies": { "@stdlib/array-float64": "^0.2.2", @@ -90,4 +91,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From 77a40e55ad59a88b7d46a82cf0b2940e6ea7770c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 29 Jul 2024 02:30:14 +0000 Subject: [PATCH 084/119] Remove files --- index.d.ts | 81 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4928 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 97640ae..0000000 --- a/index.d.ts +++ /dev/null @@ -1,81 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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'; -import { ndarray } from '@stdlib/types/ndarray'; - -/** -* Broadcasts an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* ## Notes -* -* - The function throws an error if a provided ndarray is incompatible with a provided shape. -* - If a provided ndarray has the same shape as the specified shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the specified shape, the function returns a new (base) ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to the view may affect multiple elements. If you need to write to the returned array, copy the array before performing operations which may mutate elements. -* - A returned array view is a "base" ndarray, and, thus, a returned array view does not perform bounds checking or afford any of the guarantees of the non-base ndarray constructor. The primary intent of this function is to broadcast an ndarray-like object within internal implementations and to do so with minimal overhead. -* -* @param arr - input array -* @param shape - desired shape -* @throws input array cannot have more dimensions than the desired shape -* @throws input array dimension sizes must be `1` or equal to the corresponding dimension in the provided shape -* @throws input array and desired shape must be broadcast compatible -* @returns broadcasted array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -*/ -declare function maybeBroadcastArray( arr: ndarray, shape: ArrayLike ): ndarray; - - -// EXPORTS // - -export = maybeBroadcastArray; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 47264a6..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.1-esm/index.mjs";function e(e,s){var n,a,d;if(a=s.length,(n=t(e,!1)).length===a){for(d=0;d\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArray;\n"],"names":["maybeBroadcastArray","arr","shape","sh","N","i","length","getShape","broadcast"],"mappings":";;oMAqFA,SAASA,EAAqBC,EAAKC,GAClC,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAMI,QACVH,EAAKI,EAAUN,GAAK,IAGZK,SAAWF,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,KAAQH,EAAOG,GAEvB,OAAOG,EAAWP,EAAKC,GAGzB,OAAOD,CACP,CAED,OAAOO,EAAWP,EAAKC,EACxB"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index d02ab5b..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 0fdf09e418dbd433f23e40301f8a8a7d66a33f29 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 29 Jul 2024 02:30:31 +0000 Subject: [PATCH 085/119] 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 | 140 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 49 +- SECURITY.md | 5 - benchmark/benchmark.js | 290 -- benchmark/benchmark.ndims.js | 110 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 68 - docs/types/test.ts | 94 - examples/index.js | 45 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 68 - lib/main.js | 112 - package.json | 64 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 514 --- 43 files changed, 4871 insertions(+), 4816 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/benchmark.ndims.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (97%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/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 740d5ce..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/maybe-broadcast-array) 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 4fadc31..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/maybe-broadcast-array) 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 31edc84..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: '45 9 * * 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 + + ```
@@ -173,7 +164,7 @@ for ( i = 0; i < N; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -236,11 +227,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-maybe-broadcast-array/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor +[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor/tree/esm -[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes +[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm
diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index ba5f734..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,290 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var ndarrayBase = require( '@stdlib/ndarray-base-ctor' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArray = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::base_ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::base_ndarray,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( out.shape[ 0 ] !== shape[ 0 ] ) { - b.fail( 'unexpected result' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.ndims.js b/benchmark/benchmark.ndims.js deleted file mode 100644 index 739b74c..0000000 --- a/benchmark/benchmark.ndims.js +++ /dev/null @@ -1,110 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var array = require( '@stdlib/ndarray-array' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} ndims - number of dimensions to which to broadcast -* @returns {Function} benchmark function -*/ -function createBenchmark( ndims ) { - var shape; - var sh; - var x; - var i; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - sh = x.shape; - - shape = []; - for ( i = 0; i < ndims; i++ ) { - shape.push( 0 ); - } - for ( i = ndims; i >= 1; i-- ) { - if ( i > sh.length ) { - shape[ ndims-i ] = 5; - } else { - shape[ ndims-i ] = sh[ i-1 ]; - } - } - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( x, shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var min; - var max; - var f; - var i; - - min = 2; - max = 10; - - for ( i = min; i <= max; i++ ) { - f = createBenchmark( i ); - bench( pkg+'::ndarray,2d:from_ndims=2,to_ndims='+i, f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index e45b5c4..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/maybe-broadcast-array" -%% click B href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/maybe-broadcast-array -[production-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 71859ce..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import maybeBroadcastArray from '../docs/types/index'; -export = maybeBroadcastArray; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 4b04e84..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var o=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var s=o(function(l,n){ -var u=require('@stdlib/ndarray-base-broadcast-array/dist'),v=require('@stdlib/ndarray-base-shape/dist');function c(e,r){var i,a,t;if(a=r.length,i=v(e,!1),i.length===a){for(t=0;t\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nmodule.exports = maybeBroadcastArray;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape.\n*\n* @module @stdlib/ndarray-base-maybe-broadcast-array\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var maybeBroadcastArray = require( '@stdlib/ndarray-base-maybe-broadcast-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAY,QAAS,sCAAuC,EAC5DC,EAAW,QAAS,4BAA6B,EA8DrD,SAASC,EAAqBC,EAAKC,EAAQ,CAC1C,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAM,OACVC,EAAKJ,EAAUE,EAAK,EAAM,EAGrBE,EAAG,SAAWC,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,CAAE,IAAMH,EAAOG,CAAE,EAEzB,OAAOP,EAAWG,EAAKC,CAAM,EAG/B,OAAOD,CACR,CAEA,OAAOH,EAAWG,EAAKC,CAAM,CAC9B,CAKAL,EAAO,QAAUG,ICjDjB,IAAIM,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "broadcast", "getShape", "maybeBroadcastArray", "arr", "shape", "sh", "N", "i", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 01ecba8..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,68 +0,0 @@ - -{{alias}}( arr, shape ) - Broadcasts an ndarray to a specified shape if and only if the specified - shape differs from the provided ndarray's shape. - - If a provided ndarray has the same shape as the specified shape, the - function returns the provided ndarray. - - If a provided ndarray has a different (broadcast compatible) shape than the - specified shape, the function returns a new (base) ndarray view of the - provided ndarray's data. The view is typically **not** contiguous. As more - than one element of a returned view may refer to the same memory location, - writing to the view may affect multiple elements. If you need to write to - the returned array, copy the array before performing operations which may - mutate elements. - - A returned array view is a "base" ndarray, and, thus, a returned array view - does not perform bounds checking or afford any of the guarantees of the non- - base ndarray constructor. The primary intent of this function is to - broadcast an ndarray-like object within internal implementations and to do - so with minimal overhead. - - The function throws an error if a provided ndarray is incompatible with a - provided shape. - - Parameters - ---------- - arr: ndarray - Input array. - - shape: ArrayLikeObject - Desired shape. - - Returns - ------- - out: ndarray - Broadcasted array. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > var sh = x.shape - [ 2, 2 ] - > var y = {{alias}}( x, [ 3, 2, 2 ] ) - - > sh = y.shape - [ 3, 2, 2 ] - > var v = y.get( 0, 0, 0 ) - 1 - > v = y.get( 0, 0, 1 ) - 2 - > v = y.get( 0, 1, 0 ) - 3 - > v = y.get( 0, 1, 1 ) - 4 - > v = y.get( 1, 0, 0 ) - 1 - > v = y.get( 1, 1, 0 ) - 3 - > v = y.get( 2, 0, 0 ) - 1 - > v = y.get( 2, 1, 1 ) - 4 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index d7a1a62..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,94 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ndarray } from '@stdlib/types/ndarray'; -import maybeBroadcastArray = require( './index' ); - -/** -* Mock function to create an ndarray-like object. -* -* @return ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns an ndarray... -{ - const x = array(); - - maybeBroadcastArray( x, [ 2, 2, 2 ] ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is not provided a first argument which is an ndarray... -{ - maybeBroadcastArray( '5', [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( 5, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( true, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( false, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( null, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( {}, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( [ '5' ], [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( ( x: number ): number => x, [ 2, 2, 2 ] ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a second argument which is an array-like object containing numbers... -{ - const x = array(); - - maybeBroadcastArray( x, '5' ); // $ExpectError - maybeBroadcastArray( x, 5 ); // $ExpectError - maybeBroadcastArray( x, true ); // $ExpectError - maybeBroadcastArray( x, false ); // $ExpectError - maybeBroadcastArray( x, null ); // $ExpectError - maybeBroadcastArray( x, {} ); // $ExpectError - maybeBroadcastArray( x, [ '5' ] ); // $ExpectError - maybeBroadcastArray( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - - maybeBroadcastArray(); // $ExpectError - maybeBroadcastArray( x ); // $ExpectError - maybeBroadcastArray( x, [ 1, 2, 3 ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index e787d6e..0000000 --- a/examples/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 array = require( '@stdlib/ndarray-array' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var maybeBroadcastArray = require( './../lib' ); - -// Create a 2x2 array: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -// returns - -// Broadcast the array to 3x2x2: -var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -// returns - -// Retrieve the shape: -var sh = y.shape; -// returns [ 3, 2, 2 ] - -// Retrieve the number of elements: -var N = numel( sh ); - -// Loop through the array elements... -var i; -for ( i = 0; i < N; i++ ) { - console.log( 'Y[%s] = %d', ind2sub( sh, i ).join( ', ' ), y.iget( i ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 97% rename from docs/types/index.d.ts rename to index.d.ts index f354818..97640ae 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..8c83ac5 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.2-esm/index.mjs";function e(e,s){var n,a,d;if(a=s.length,(n=t(e,!1)).length===a){for(d=0;d\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArray;\n"],"names":["maybeBroadcastArray","arr","shape","sh","N","i","length","getShape","broadcast"],"mappings":";;oMAqFA,SAASA,EAAqBC,EAAKC,GAClC,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAMI,QACVH,EAAKI,EAAUN,GAAK,IAGZK,SAAWF,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,KAAQH,EAAOG,GAEvB,OAAOG,EAAWP,EAAKC,GAGzB,OAAOD,CACP,CAED,OAAOO,EAAWP,EAAKC,EACxB"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 834e930..0000000 --- a/lib/index.js +++ /dev/null @@ -1,68 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* @module @stdlib/ndarray-base-maybe-broadcast-array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var maybeBroadcastArray = require( '@stdlib/ndarray-base-maybe-broadcast-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -*/ - -// 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 e59ca1d..0000000 --- a/lib/main.js +++ /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. -*/ - -'use strict'; - -// MODULES // - -var broadcast = require( '@stdlib/ndarray-base-broadcast-array' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); - - -// MAIN // - -/** -* Broadcasts an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* ## Notes -* -* - If a provided ndarray has the same shape as the specified shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the specified shape, the function returns a new (base) ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to the view may affect multiple elements. If you need to write to the returned array, copy the array before performing operations which may mutate elements. -* -* @param {ndarray} arr - input array -* @param {NonNegativeIntegerArray} shape - desired shape -* @throws {Error} input array cannot have more dimensions than the desired shape -* @throws {Error} input array dimension sizes must be `1` or equal to the corresponding dimension in the provided shape -* @throws {Error} input array and desired shape must be broadcast compatible -* @returns {ndarray} broadcasted array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var y = maybeBroadcastArray( x, [ 3, 2 ] ); -* // throws -*/ -function maybeBroadcastArray( arr, shape ) { - var sh; - var N; - var i; - - N = shape.length; - sh = getShape( arr, false ); - - // Check whether we need to broadcast the input array... - if ( sh.length === N ) { - for ( i = 0; i < N; i++ ) { - // Check whether dimensions match... - if ( sh[ i ] !== shape[ i ] ) { - // We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape... - return broadcast( arr, shape ); - } - } - return arr; - } - // If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape... - return broadcast( arr, shape ); -} - - -// EXPORTS // - -module.exports = maybeBroadcastArray; diff --git a/package.json b/package.json index f26e17b..10732c7 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Broadcast an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's 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", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-base-broadcast-array": "^0.2.1", - "@stdlib/ndarray-base-shape": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-ctor": "^0.2.1", - "@stdlib/ndarray-ind2sub": "^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.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -86,9 +29,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..36b29a9 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 7e8e63f..0000000 --- a/test/test.js +++ /dev/null @@ -1,514 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 array = require( '@stdlib/ndarray-array' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var maybeBroadcastArray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof maybeBroadcastArray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a desired shape which has fewer dimensions than the input array', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 ] - }); - - values = [ - [], - [ 2 ], - [ 2, 2 ], - [ 2, 2, 2 ], - [ 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2, 2, 2 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided a shape with '+values[ i ].length+' dimension' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape having a dimension whose size is less than the corresponding dimension in the input array', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 10, 1 ], - [ 10, 10, 2 ], - [ 10, 10, 9 ], - [ 10, 1, 10 ], - [ 10, 2, 10 ], - [ 10, 9, 10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape and an input array shape which are broadcast-incompatible', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 20, 10 ], - [ 10, 10, 100 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function returns a "base" ndarray instance', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = maybeBroadcastArray( x, [ 2, 2, 2 ] ); - - t.notEqual( y, x, 'returns new instance' ); - t.strictEqual( y instanceof ndarray, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view over the input array data buffer', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = maybeBroadcastArray( x, [ 2, 2, 2 ] ); - - t.strictEqual( y.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; strides)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, -1 ], 3, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; strides)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, 1 ], 2, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; non-contiguous)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ 4, 2 ], 1, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 5 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 7 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (column-major)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'column-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (same shape)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2, 2 ], - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - // Should return the same instance: - t.strictEqual( y, x, 'returns expected value' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 1, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 1, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (same number of dimensions)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1, 2 ], - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (singleton dimension)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (singleton dimension)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 1, 2 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (0-dimensional array)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1 ]; - x = ndarray( 'generic', data, [], [ 0 ], 0, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); From 5de1061de5b7a39a3ef61f4cc12453e347387d6b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 29 Jul 2024 02:31:08 +0000 Subject: [PATCH 086/119] Update README.md for ESM bundle v0.2.2 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e249134..a169ce6 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ limitations under the License. ## Usage ```javascript -import maybeBroadcastArray from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-maybe-broadcast-array@esm/index.mjs'; +import maybeBroadcastArray from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-maybe-broadcast-array@v0.2.2-esm/index.mjs'; ``` #### maybeBroadcastArray( arr, shape ) @@ -107,7 +107,7 @@ var y = maybeBroadcastArray( x, [ 2, 2, 2 ] ); import array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-array@esm/index.mjs'; import numel from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@esm/index.mjs'; import ind2sub from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ind2sub@esm/index.mjs'; -import maybeBroadcastArray from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-maybe-broadcast-array@esm/index.mjs'; +import maybeBroadcastArray from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-maybe-broadcast-array@v0.2.2-esm/index.mjs'; // Create a 2x2 array: var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); From be62d7cf515ae5e0f6a8467660fb369916be3eb8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 29 Jul 2024 02:31:08 +0000 Subject: [PATCH 087/119] Auto-generated commit --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a169ce6..7d73cac 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,11 @@ limitations under the License. ## Usage +```javascript +import maybeBroadcastArray from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-maybe-broadcast-array@esm/index.mjs'; +``` +The previous example will load the latest bundled code from the esm branch. Alternatively, you may load a specific version by loading the file from one of the [tagged bundles](https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tags). For example, + ```javascript import maybeBroadcastArray from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-maybe-broadcast-array@v0.2.2-esm/index.mjs'; ``` @@ -107,7 +112,7 @@ var y = maybeBroadcastArray( x, [ 2, 2, 2 ] ); import array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-array@esm/index.mjs'; import numel from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@esm/index.mjs'; import ind2sub from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ind2sub@esm/index.mjs'; -import maybeBroadcastArray from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-maybe-broadcast-array@v0.2.2-esm/index.mjs'; +import maybeBroadcastArray from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-maybe-broadcast-array@esm/index.mjs'; // Create a 2x2 array: var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); From 6cf087c1c2f6cb0006b95f7d4eed31edcabc8197 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 29 Jul 2024 02:34:03 +0000 Subject: [PATCH 088/119] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 0aee35d..70284b6 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,8 @@ "dependencies": { "@stdlib/ndarray-base-broadcast-array": "^0.2.2", "@stdlib/ndarray-base-shape": "^0.2.2", - "@stdlib/types": "^0.3.2" + "@stdlib/types": "^0.3.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, "devDependencies": { "@stdlib/array-float64": "^0.2.2", @@ -90,4 +91,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From 2b17736e7374e9d0746a4c49838199c1f2c65856 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 29 Jul 2024 02:34:29 +0000 Subject: [PATCH 089/119] Remove files --- index.d.ts | 81 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4928 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 97640ae..0000000 --- a/index.d.ts +++ /dev/null @@ -1,81 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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'; -import { ndarray } from '@stdlib/types/ndarray'; - -/** -* Broadcasts an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* ## Notes -* -* - The function throws an error if a provided ndarray is incompatible with a provided shape. -* - If a provided ndarray has the same shape as the specified shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the specified shape, the function returns a new (base) ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to the view may affect multiple elements. If you need to write to the returned array, copy the array before performing operations which may mutate elements. -* - A returned array view is a "base" ndarray, and, thus, a returned array view does not perform bounds checking or afford any of the guarantees of the non-base ndarray constructor. The primary intent of this function is to broadcast an ndarray-like object within internal implementations and to do so with minimal overhead. -* -* @param arr - input array -* @param shape - desired shape -* @throws input array cannot have more dimensions than the desired shape -* @throws input array dimension sizes must be `1` or equal to the corresponding dimension in the provided shape -* @throws input array and desired shape must be broadcast compatible -* @returns broadcasted array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -*/ -declare function maybeBroadcastArray( arr: ndarray, shape: ArrayLike ): ndarray; - - -// EXPORTS // - -export = maybeBroadcastArray; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 8c83ac5..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.2-esm/index.mjs";function e(e,s){var n,a,d;if(a=s.length,(n=t(e,!1)).length===a){for(d=0;d\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArray;\n"],"names":["maybeBroadcastArray","arr","shape","sh","N","i","length","getShape","broadcast"],"mappings":";;oMAqFA,SAASA,EAAqBC,EAAKC,GAClC,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAMI,QACVH,EAAKI,EAAUN,GAAK,IAGZK,SAAWF,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,KAAQH,EAAOG,GAEvB,OAAOG,EAAWP,EAAKC,GAGzB,OAAOD,CACP,CAED,OAAOO,EAAWP,EAAKC,EACxB"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 36b29a9..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 0983438a7716b5ffee84be3dbda176f4581a9f30 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 29 Jul 2024 02:34:50 +0000 Subject: [PATCH 090/119] 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 | 150 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 49 +- SECURITY.md | 5 - benchmark/benchmark.js | 290 -- benchmark/benchmark.ndims.js | 110 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 68 - docs/types/test.ts | 94 - examples/index.js | 45 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 68 - lib/main.js | 112 - package.json | 64 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 514 --- 43 files changed, 4871 insertions(+), 4826 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/benchmark.ndims.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (97%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/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 740d5ce..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/maybe-broadcast-array) 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 4fadc31..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/maybe-broadcast-array) 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 31edc84..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: '45 9 * * 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 + + ```
@@ -173,7 +164,7 @@ for ( i = 0; i < N; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -236,11 +227,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-maybe-broadcast-array/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor +[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor/tree/esm -[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes +[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm
diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index ba5f734..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,290 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var ndarrayBase = require( '@stdlib/ndarray-base-ctor' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArray = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::base_ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::base_ndarray,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( out.shape[ 0 ] !== shape[ 0 ] ) { - b.fail( 'unexpected result' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.ndims.js b/benchmark/benchmark.ndims.js deleted file mode 100644 index 739b74c..0000000 --- a/benchmark/benchmark.ndims.js +++ /dev/null @@ -1,110 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var array = require( '@stdlib/ndarray-array' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} ndims - number of dimensions to which to broadcast -* @returns {Function} benchmark function -*/ -function createBenchmark( ndims ) { - var shape; - var sh; - var x; - var i; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - sh = x.shape; - - shape = []; - for ( i = 0; i < ndims; i++ ) { - shape.push( 0 ); - } - for ( i = ndims; i >= 1; i-- ) { - if ( i > sh.length ) { - shape[ ndims-i ] = 5; - } else { - shape[ ndims-i ] = sh[ i-1 ]; - } - } - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( x, shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var min; - var max; - var f; - var i; - - min = 2; - max = 10; - - for ( i = min; i <= max; i++ ) { - f = createBenchmark( i ); - bench( pkg+'::ndarray,2d:from_ndims=2,to_ndims='+i, f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index e45b5c4..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/maybe-broadcast-array" -%% click B href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/maybe-broadcast-array -[production-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 71859ce..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import maybeBroadcastArray from '../docs/types/index'; -export = maybeBroadcastArray; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 4b04e84..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var o=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var s=o(function(l,n){ -var u=require('@stdlib/ndarray-base-broadcast-array/dist'),v=require('@stdlib/ndarray-base-shape/dist');function c(e,r){var i,a,t;if(a=r.length,i=v(e,!1),i.length===a){for(t=0;t\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nmodule.exports = maybeBroadcastArray;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape.\n*\n* @module @stdlib/ndarray-base-maybe-broadcast-array\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var maybeBroadcastArray = require( '@stdlib/ndarray-base-maybe-broadcast-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAY,QAAS,sCAAuC,EAC5DC,EAAW,QAAS,4BAA6B,EA8DrD,SAASC,EAAqBC,EAAKC,EAAQ,CAC1C,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAM,OACVC,EAAKJ,EAAUE,EAAK,EAAM,EAGrBE,EAAG,SAAWC,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,CAAE,IAAMH,EAAOG,CAAE,EAEzB,OAAOP,EAAWG,EAAKC,CAAM,EAG/B,OAAOD,CACR,CAEA,OAAOH,EAAWG,EAAKC,CAAM,CAC9B,CAKAL,EAAO,QAAUG,ICjDjB,IAAIM,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "broadcast", "getShape", "maybeBroadcastArray", "arr", "shape", "sh", "N", "i", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 01ecba8..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,68 +0,0 @@ - -{{alias}}( arr, shape ) - Broadcasts an ndarray to a specified shape if and only if the specified - shape differs from the provided ndarray's shape. - - If a provided ndarray has the same shape as the specified shape, the - function returns the provided ndarray. - - If a provided ndarray has a different (broadcast compatible) shape than the - specified shape, the function returns a new (base) ndarray view of the - provided ndarray's data. The view is typically **not** contiguous. As more - than one element of a returned view may refer to the same memory location, - writing to the view may affect multiple elements. If you need to write to - the returned array, copy the array before performing operations which may - mutate elements. - - A returned array view is a "base" ndarray, and, thus, a returned array view - does not perform bounds checking or afford any of the guarantees of the non- - base ndarray constructor. The primary intent of this function is to - broadcast an ndarray-like object within internal implementations and to do - so with minimal overhead. - - The function throws an error if a provided ndarray is incompatible with a - provided shape. - - Parameters - ---------- - arr: ndarray - Input array. - - shape: ArrayLikeObject - Desired shape. - - Returns - ------- - out: ndarray - Broadcasted array. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > var sh = x.shape - [ 2, 2 ] - > var y = {{alias}}( x, [ 3, 2, 2 ] ) - - > sh = y.shape - [ 3, 2, 2 ] - > var v = y.get( 0, 0, 0 ) - 1 - > v = y.get( 0, 0, 1 ) - 2 - > v = y.get( 0, 1, 0 ) - 3 - > v = y.get( 0, 1, 1 ) - 4 - > v = y.get( 1, 0, 0 ) - 1 - > v = y.get( 1, 1, 0 ) - 3 - > v = y.get( 2, 0, 0 ) - 1 - > v = y.get( 2, 1, 1 ) - 4 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index d7a1a62..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,94 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ndarray } from '@stdlib/types/ndarray'; -import maybeBroadcastArray = require( './index' ); - -/** -* Mock function to create an ndarray-like object. -* -* @return ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns an ndarray... -{ - const x = array(); - - maybeBroadcastArray( x, [ 2, 2, 2 ] ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is not provided a first argument which is an ndarray... -{ - maybeBroadcastArray( '5', [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( 5, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( true, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( false, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( null, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( {}, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( [ '5' ], [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( ( x: number ): number => x, [ 2, 2, 2 ] ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a second argument which is an array-like object containing numbers... -{ - const x = array(); - - maybeBroadcastArray( x, '5' ); // $ExpectError - maybeBroadcastArray( x, 5 ); // $ExpectError - maybeBroadcastArray( x, true ); // $ExpectError - maybeBroadcastArray( x, false ); // $ExpectError - maybeBroadcastArray( x, null ); // $ExpectError - maybeBroadcastArray( x, {} ); // $ExpectError - maybeBroadcastArray( x, [ '5' ] ); // $ExpectError - maybeBroadcastArray( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - - maybeBroadcastArray(); // $ExpectError - maybeBroadcastArray( x ); // $ExpectError - maybeBroadcastArray( x, [ 1, 2, 3 ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index e787d6e..0000000 --- a/examples/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 array = require( '@stdlib/ndarray-array' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var maybeBroadcastArray = require( './../lib' ); - -// Create a 2x2 array: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -// returns - -// Broadcast the array to 3x2x2: -var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -// returns - -// Retrieve the shape: -var sh = y.shape; -// returns [ 3, 2, 2 ] - -// Retrieve the number of elements: -var N = numel( sh ); - -// Loop through the array elements... -var i; -for ( i = 0; i < N; i++ ) { - console.log( 'Y[%s] = %d', ind2sub( sh, i ).join( ', ' ), y.iget( i ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 97% rename from docs/types/index.d.ts rename to index.d.ts index f354818..97640ae 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..7290520 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.2-esm/index.mjs";function e(e,s){var n,a,d;if(a=s.length,(n=t(e,!1)).length===a){for(d=0;d\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArray;\n"],"names":["maybeBroadcastArray","arr","shape","sh","N","i","length","getShape","broadcast"],"mappings":";;oMAqFA,SAASA,EAAqBC,EAAKC,GAClC,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAMI,QACVH,EAAKI,EAAUN,GAAK,IAGZK,SAAWF,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,KAAQH,EAAOG,GAEvB,OAAOG,EAAWP,EAAKC,GAGzB,OAAOD,CACP,CAED,OAAOO,EAAWP,EAAKC,EACxB"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 834e930..0000000 --- a/lib/index.js +++ /dev/null @@ -1,68 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* @module @stdlib/ndarray-base-maybe-broadcast-array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var maybeBroadcastArray = require( '@stdlib/ndarray-base-maybe-broadcast-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -*/ - -// 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 e59ca1d..0000000 --- a/lib/main.js +++ /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. -*/ - -'use strict'; - -// MODULES // - -var broadcast = require( '@stdlib/ndarray-base-broadcast-array' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); - - -// MAIN // - -/** -* Broadcasts an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* ## Notes -* -* - If a provided ndarray has the same shape as the specified shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the specified shape, the function returns a new (base) ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to the view may affect multiple elements. If you need to write to the returned array, copy the array before performing operations which may mutate elements. -* -* @param {ndarray} arr - input array -* @param {NonNegativeIntegerArray} shape - desired shape -* @throws {Error} input array cannot have more dimensions than the desired shape -* @throws {Error} input array dimension sizes must be `1` or equal to the corresponding dimension in the provided shape -* @throws {Error} input array and desired shape must be broadcast compatible -* @returns {ndarray} broadcasted array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var y = maybeBroadcastArray( x, [ 3, 2 ] ); -* // throws -*/ -function maybeBroadcastArray( arr, shape ) { - var sh; - var N; - var i; - - N = shape.length; - sh = getShape( arr, false ); - - // Check whether we need to broadcast the input array... - if ( sh.length === N ) { - for ( i = 0; i < N; i++ ) { - // Check whether dimensions match... - if ( sh[ i ] !== shape[ i ] ) { - // We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape... - return broadcast( arr, shape ); - } - } - return arr; - } - // If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape... - return broadcast( arr, shape ); -} - - -// EXPORTS // - -module.exports = maybeBroadcastArray; diff --git a/package.json b/package.json index 70284b6..489e5cf 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.3", "description": "Broadcast an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's 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", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-base-broadcast-array": "^0.2.2", - "@stdlib/ndarray-base-shape": "^0.2.2", - "@stdlib/types": "^0.3.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-ctor": "^0.2.1", - "@stdlib/ndarray-ind2sub": "^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.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -86,9 +29,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..a9abfed --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 7e8e63f..0000000 --- a/test/test.js +++ /dev/null @@ -1,514 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 array = require( '@stdlib/ndarray-array' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var maybeBroadcastArray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof maybeBroadcastArray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a desired shape which has fewer dimensions than the input array', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 ] - }); - - values = [ - [], - [ 2 ], - [ 2, 2 ], - [ 2, 2, 2 ], - [ 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2, 2, 2 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided a shape with '+values[ i ].length+' dimension' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape having a dimension whose size is less than the corresponding dimension in the input array', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 10, 1 ], - [ 10, 10, 2 ], - [ 10, 10, 9 ], - [ 10, 1, 10 ], - [ 10, 2, 10 ], - [ 10, 9, 10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape and an input array shape which are broadcast-incompatible', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 20, 10 ], - [ 10, 10, 100 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function returns a "base" ndarray instance', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = maybeBroadcastArray( x, [ 2, 2, 2 ] ); - - t.notEqual( y, x, 'returns new instance' ); - t.strictEqual( y instanceof ndarray, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view over the input array data buffer', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = maybeBroadcastArray( x, [ 2, 2, 2 ] ); - - t.strictEqual( y.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; strides)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, -1 ], 3, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; strides)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, 1 ], 2, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; non-contiguous)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ 4, 2 ], 1, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 5 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 7 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (column-major)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'column-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (same shape)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2, 2 ], - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - // Should return the same instance: - t.strictEqual( y, x, 'returns expected value' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 1, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 1, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (same number of dimensions)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1, 2 ], - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (singleton dimension)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (singleton dimension)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 1, 2 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (0-dimensional array)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1 ]; - x = ndarray( 'generic', data, [], [ 0 ], 0, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); From 4b1c6bac078d6a9c86992f5535b4dd66656312fa Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 29 Jul 2024 02:35:19 +0000 Subject: [PATCH 091/119] Update README.md for ESM bundle v0.2.3 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6d26df3..d8d9cd7 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ limitations under the License. ## Usage ```javascript -import maybeBroadcastArray from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-maybe-broadcast-array@esm/index.mjs'; +import maybeBroadcastArray from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-maybe-broadcast-array@v0.2.3-esm/index.mjs'; ``` #### maybeBroadcastArray( arr, shape ) @@ -107,7 +107,7 @@ var y = maybeBroadcastArray( x, [ 2, 2, 2 ] ); import array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-array@esm/index.mjs'; import numel from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@esm/index.mjs'; import ind2sub from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ind2sub@esm/index.mjs'; -import maybeBroadcastArray from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-maybe-broadcast-array@esm/index.mjs'; +import maybeBroadcastArray from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-maybe-broadcast-array@v0.2.3-esm/index.mjs'; // Create a 2x2 array: var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); From 5177bdbd46ed3690a73726d455621b5a6f774749 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 29 Jul 2024 02:35:20 +0000 Subject: [PATCH 092/119] Auto-generated commit --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d8d9cd7..4b396a2 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,11 @@ limitations under the License. ## Usage +```javascript +import maybeBroadcastArray from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-maybe-broadcast-array@esm/index.mjs'; +``` +The previous example will load the latest bundled code from the esm branch. Alternatively, you may load a specific version by loading the file from one of the [tagged bundles](https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tags). For example, + ```javascript import maybeBroadcastArray from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-maybe-broadcast-array@v0.2.3-esm/index.mjs'; ``` @@ -107,7 +112,7 @@ var y = maybeBroadcastArray( x, [ 2, 2, 2 ] ); import array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-array@esm/index.mjs'; import numel from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@esm/index.mjs'; import ind2sub from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ind2sub@esm/index.mjs'; -import maybeBroadcastArray from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-maybe-broadcast-array@v0.2.3-esm/index.mjs'; +import maybeBroadcastArray from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-maybe-broadcast-array@esm/index.mjs'; // Create a 2x2 array: var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); From 02b27c84bab8324210046ecc1012f791517c37de Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Aug 2024 07:51:40 +0000 Subject: [PATCH 093/119] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 9f093cd..dd6fef6 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,8 @@ "dependencies": { "@stdlib/ndarray-base-broadcast-array": "^0.2.2", "@stdlib/ndarray-base-shape": "^0.2.2", - "@stdlib/types": "^0.3.2" + "@stdlib/types": "^0.3.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, "devDependencies": { "@stdlib/array-float64": "^0.2.2", @@ -90,4 +91,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From 170c7793d1dd3d552a44eb0fc544bc9dfb9f628c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Aug 2024 12:46:26 +0000 Subject: [PATCH 094/119] Remove files --- index.d.ts | 81 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4928 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 97640ae..0000000 --- a/index.d.ts +++ /dev/null @@ -1,81 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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'; -import { ndarray } from '@stdlib/types/ndarray'; - -/** -* Broadcasts an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* ## Notes -* -* - The function throws an error if a provided ndarray is incompatible with a provided shape. -* - If a provided ndarray has the same shape as the specified shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the specified shape, the function returns a new (base) ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to the view may affect multiple elements. If you need to write to the returned array, copy the array before performing operations which may mutate elements. -* - A returned array view is a "base" ndarray, and, thus, a returned array view does not perform bounds checking or afford any of the guarantees of the non-base ndarray constructor. The primary intent of this function is to broadcast an ndarray-like object within internal implementations and to do so with minimal overhead. -* -* @param arr - input array -* @param shape - desired shape -* @throws input array cannot have more dimensions than the desired shape -* @throws input array dimension sizes must be `1` or equal to the corresponding dimension in the provided shape -* @throws input array and desired shape must be broadcast compatible -* @returns broadcasted array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -*/ -declare function maybeBroadcastArray( arr: ndarray, shape: ArrayLike ): ndarray; - - -// EXPORTS // - -export = maybeBroadcastArray; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 7290520..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.2-esm/index.mjs";function e(e,s){var n,a,d;if(a=s.length,(n=t(e,!1)).length===a){for(d=0;d\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArray;\n"],"names":["maybeBroadcastArray","arr","shape","sh","N","i","length","getShape","broadcast"],"mappings":";;oMAqFA,SAASA,EAAqBC,EAAKC,GAClC,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAMI,QACVH,EAAKI,EAAUN,GAAK,IAGZK,SAAWF,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,KAAQH,EAAOG,GAEvB,OAAOG,EAAWP,EAAKC,GAGzB,OAAOD,CACP,CAED,OAAOO,EAAWP,EAAKC,EACxB"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index a9abfed..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From ff6cbfe60c9b8866d26d02faa4c7c942987aae52 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Aug 2024 12:46:44 +0000 Subject: [PATCH 095/119] 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 | 98 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 49 +- SECURITY.md | 5 - benchmark/benchmark.js | 290 -- benchmark/benchmark.ndims.js | 110 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 68 - docs/types/test.ts | 94 - examples/index.js | 45 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 68 - lib/main.js | 112 - package.json | 64 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 514 --- 44 files changed, 4871 insertions(+), 4775 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/benchmark.ndims.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (97%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/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 71cf5fe..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-08-01T05:46:14.280Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 740d5ce..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/maybe-broadcast-array) 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 4fadc31..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/maybe-broadcast-array) 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 31edc84..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: '45 9 * * 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 + + ```
@@ -173,7 +164,7 @@ for ( i = 0; i < N; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -236,11 +227,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-maybe-broadcast-array/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor +[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor/tree/esm -[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes +[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm
diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index ba5f734..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,290 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var ndarrayBase = require( '@stdlib/ndarray-base-ctor' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArray = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::base_ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::base_ndarray,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( out.shape[ 0 ] !== shape[ 0 ] ) { - b.fail( 'unexpected result' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.ndims.js b/benchmark/benchmark.ndims.js deleted file mode 100644 index 739b74c..0000000 --- a/benchmark/benchmark.ndims.js +++ /dev/null @@ -1,110 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var array = require( '@stdlib/ndarray-array' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} ndims - number of dimensions to which to broadcast -* @returns {Function} benchmark function -*/ -function createBenchmark( ndims ) { - var shape; - var sh; - var x; - var i; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - sh = x.shape; - - shape = []; - for ( i = 0; i < ndims; i++ ) { - shape.push( 0 ); - } - for ( i = ndims; i >= 1; i-- ) { - if ( i > sh.length ) { - shape[ ndims-i ] = 5; - } else { - shape[ ndims-i ] = sh[ i-1 ]; - } - } - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( x, shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var min; - var max; - var f; - var i; - - min = 2; - max = 10; - - for ( i = min; i <= max; i++ ) { - f = createBenchmark( i ); - bench( pkg+'::ndarray,2d:from_ndims=2,to_ndims='+i, f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index e45b5c4..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/maybe-broadcast-array" -%% click B href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/maybe-broadcast-array -[production-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 71859ce..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import maybeBroadcastArray from '../docs/types/index'; -export = maybeBroadcastArray; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 4b04e84..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var o=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var s=o(function(l,n){ -var u=require('@stdlib/ndarray-base-broadcast-array/dist'),v=require('@stdlib/ndarray-base-shape/dist');function c(e,r){var i,a,t;if(a=r.length,i=v(e,!1),i.length===a){for(t=0;t\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nmodule.exports = maybeBroadcastArray;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape.\n*\n* @module @stdlib/ndarray-base-maybe-broadcast-array\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var maybeBroadcastArray = require( '@stdlib/ndarray-base-maybe-broadcast-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAY,QAAS,sCAAuC,EAC5DC,EAAW,QAAS,4BAA6B,EA8DrD,SAASC,EAAqBC,EAAKC,EAAQ,CAC1C,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAM,OACVC,EAAKJ,EAAUE,EAAK,EAAM,EAGrBE,EAAG,SAAWC,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,CAAE,IAAMH,EAAOG,CAAE,EAEzB,OAAOP,EAAWG,EAAKC,CAAM,EAG/B,OAAOD,CACR,CAEA,OAAOH,EAAWG,EAAKC,CAAM,CAC9B,CAKAL,EAAO,QAAUG,ICjDjB,IAAIM,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "broadcast", "getShape", "maybeBroadcastArray", "arr", "shape", "sh", "N", "i", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 01ecba8..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,68 +0,0 @@ - -{{alias}}( arr, shape ) - Broadcasts an ndarray to a specified shape if and only if the specified - shape differs from the provided ndarray's shape. - - If a provided ndarray has the same shape as the specified shape, the - function returns the provided ndarray. - - If a provided ndarray has a different (broadcast compatible) shape than the - specified shape, the function returns a new (base) ndarray view of the - provided ndarray's data. The view is typically **not** contiguous. As more - than one element of a returned view may refer to the same memory location, - writing to the view may affect multiple elements. If you need to write to - the returned array, copy the array before performing operations which may - mutate elements. - - A returned array view is a "base" ndarray, and, thus, a returned array view - does not perform bounds checking or afford any of the guarantees of the non- - base ndarray constructor. The primary intent of this function is to - broadcast an ndarray-like object within internal implementations and to do - so with minimal overhead. - - The function throws an error if a provided ndarray is incompatible with a - provided shape. - - Parameters - ---------- - arr: ndarray - Input array. - - shape: ArrayLikeObject - Desired shape. - - Returns - ------- - out: ndarray - Broadcasted array. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > var sh = x.shape - [ 2, 2 ] - > var y = {{alias}}( x, [ 3, 2, 2 ] ) - - > sh = y.shape - [ 3, 2, 2 ] - > var v = y.get( 0, 0, 0 ) - 1 - > v = y.get( 0, 0, 1 ) - 2 - > v = y.get( 0, 1, 0 ) - 3 - > v = y.get( 0, 1, 1 ) - 4 - > v = y.get( 1, 0, 0 ) - 1 - > v = y.get( 1, 1, 0 ) - 3 - > v = y.get( 2, 0, 0 ) - 1 - > v = y.get( 2, 1, 1 ) - 4 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index d7a1a62..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,94 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ndarray } from '@stdlib/types/ndarray'; -import maybeBroadcastArray = require( './index' ); - -/** -* Mock function to create an ndarray-like object. -* -* @return ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns an ndarray... -{ - const x = array(); - - maybeBroadcastArray( x, [ 2, 2, 2 ] ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is not provided a first argument which is an ndarray... -{ - maybeBroadcastArray( '5', [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( 5, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( true, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( false, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( null, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( {}, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( [ '5' ], [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( ( x: number ): number => x, [ 2, 2, 2 ] ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a second argument which is an array-like object containing numbers... -{ - const x = array(); - - maybeBroadcastArray( x, '5' ); // $ExpectError - maybeBroadcastArray( x, 5 ); // $ExpectError - maybeBroadcastArray( x, true ); // $ExpectError - maybeBroadcastArray( x, false ); // $ExpectError - maybeBroadcastArray( x, null ); // $ExpectError - maybeBroadcastArray( x, {} ); // $ExpectError - maybeBroadcastArray( x, [ '5' ] ); // $ExpectError - maybeBroadcastArray( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - - maybeBroadcastArray(); // $ExpectError - maybeBroadcastArray( x ); // $ExpectError - maybeBroadcastArray( x, [ 1, 2, 3 ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index e787d6e..0000000 --- a/examples/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 array = require( '@stdlib/ndarray-array' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var maybeBroadcastArray = require( './../lib' ); - -// Create a 2x2 array: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -// returns - -// Broadcast the array to 3x2x2: -var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -// returns - -// Retrieve the shape: -var sh = y.shape; -// returns [ 3, 2, 2 ] - -// Retrieve the number of elements: -var N = numel( sh ); - -// Loop through the array elements... -var i; -for ( i = 0; i < N; i++ ) { - console.log( 'Y[%s] = %d', ind2sub( sh, i ).join( ', ' ), y.iget( i ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 97% rename from docs/types/index.d.ts rename to index.d.ts index f354818..97640ae 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..7290520 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.2-esm/index.mjs";function e(e,s){var n,a,d;if(a=s.length,(n=t(e,!1)).length===a){for(d=0;d\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArray;\n"],"names":["maybeBroadcastArray","arr","shape","sh","N","i","length","getShape","broadcast"],"mappings":";;oMAqFA,SAASA,EAAqBC,EAAKC,GAClC,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAMI,QACVH,EAAKI,EAAUN,GAAK,IAGZK,SAAWF,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,KAAQH,EAAOG,GAEvB,OAAOG,EAAWP,EAAKC,GAGzB,OAAOD,CACP,CAED,OAAOO,EAAWP,EAAKC,EACxB"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 834e930..0000000 --- a/lib/index.js +++ /dev/null @@ -1,68 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* @module @stdlib/ndarray-base-maybe-broadcast-array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var maybeBroadcastArray = require( '@stdlib/ndarray-base-maybe-broadcast-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -*/ - -// 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 e59ca1d..0000000 --- a/lib/main.js +++ /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. -*/ - -'use strict'; - -// MODULES // - -var broadcast = require( '@stdlib/ndarray-base-broadcast-array' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); - - -// MAIN // - -/** -* Broadcasts an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* ## Notes -* -* - If a provided ndarray has the same shape as the specified shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the specified shape, the function returns a new (base) ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to the view may affect multiple elements. If you need to write to the returned array, copy the array before performing operations which may mutate elements. -* -* @param {ndarray} arr - input array -* @param {NonNegativeIntegerArray} shape - desired shape -* @throws {Error} input array cannot have more dimensions than the desired shape -* @throws {Error} input array dimension sizes must be `1` or equal to the corresponding dimension in the provided shape -* @throws {Error} input array and desired shape must be broadcast compatible -* @returns {ndarray} broadcasted array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var y = maybeBroadcastArray( x, [ 3, 2 ] ); -* // throws -*/ -function maybeBroadcastArray( arr, shape ) { - var sh; - var N; - var i; - - N = shape.length; - sh = getShape( arr, false ); - - // Check whether we need to broadcast the input array... - if ( sh.length === N ) { - for ( i = 0; i < N; i++ ) { - // Check whether dimensions match... - if ( sh[ i ] !== shape[ i ] ) { - // We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape... - return broadcast( arr, shape ); - } - } - return arr; - } - // If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape... - return broadcast( arr, shape ); -} - - -// EXPORTS // - -module.exports = maybeBroadcastArray; diff --git a/package.json b/package.json index dd6fef6..489e5cf 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.3", "description": "Broadcast an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's 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", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-base-broadcast-array": "^0.2.2", - "@stdlib/ndarray-base-shape": "^0.2.2", - "@stdlib/types": "^0.3.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-ctor": "^0.2.2", - "@stdlib/ndarray-ind2sub": "^0.2.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -86,9 +29,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..a9abfed --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 7e8e63f..0000000 --- a/test/test.js +++ /dev/null @@ -1,514 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 array = require( '@stdlib/ndarray-array' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var maybeBroadcastArray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof maybeBroadcastArray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a desired shape which has fewer dimensions than the input array', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 ] - }); - - values = [ - [], - [ 2 ], - [ 2, 2 ], - [ 2, 2, 2 ], - [ 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2, 2, 2 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided a shape with '+values[ i ].length+' dimension' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape having a dimension whose size is less than the corresponding dimension in the input array', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 10, 1 ], - [ 10, 10, 2 ], - [ 10, 10, 9 ], - [ 10, 1, 10 ], - [ 10, 2, 10 ], - [ 10, 9, 10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape and an input array shape which are broadcast-incompatible', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 20, 10 ], - [ 10, 10, 100 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function returns a "base" ndarray instance', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = maybeBroadcastArray( x, [ 2, 2, 2 ] ); - - t.notEqual( y, x, 'returns new instance' ); - t.strictEqual( y instanceof ndarray, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view over the input array data buffer', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = maybeBroadcastArray( x, [ 2, 2, 2 ] ); - - t.strictEqual( y.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; strides)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, -1 ], 3, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; strides)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, 1 ], 2, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; non-contiguous)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ 4, 2 ], 1, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 5 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 7 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (column-major)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'column-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (same shape)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2, 2 ], - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - // Should return the same instance: - t.strictEqual( y, x, 'returns expected value' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 1, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 1, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (same number of dimensions)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1, 2 ], - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (singleton dimension)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (singleton dimension)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 1, 2 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (0-dimensional array)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1 ]; - x = ndarray( 'generic', data, [], [ 0 ], 0, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); From e20dfdc8a552223bba1ba902ca3397d0a454329d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Sep 2024 08:15:05 +0000 Subject: [PATCH 096/119] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 6c09d61..89af0b4 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,8 @@ "dependencies": { "@stdlib/ndarray-base-broadcast-array": "^0.2.2", "@stdlib/ndarray-base-shape": "^0.2.2", - "@stdlib/types": "^0.4.1" + "@stdlib/types": "^0.4.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, "devDependencies": { "@stdlib/array-float64": "^0.2.2", @@ -90,4 +91,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From c1b772495a9a9a37cb7baf1ac3a096e2a0d2378d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Sep 2024 12:36:42 +0000 Subject: [PATCH 097/119] Remove files --- index.d.ts | 81 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4928 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 97640ae..0000000 --- a/index.d.ts +++ /dev/null @@ -1,81 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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'; -import { ndarray } from '@stdlib/types/ndarray'; - -/** -* Broadcasts an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* ## Notes -* -* - The function throws an error if a provided ndarray is incompatible with a provided shape. -* - If a provided ndarray has the same shape as the specified shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the specified shape, the function returns a new (base) ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to the view may affect multiple elements. If you need to write to the returned array, copy the array before performing operations which may mutate elements. -* - A returned array view is a "base" ndarray, and, thus, a returned array view does not perform bounds checking or afford any of the guarantees of the non-base ndarray constructor. The primary intent of this function is to broadcast an ndarray-like object within internal implementations and to do so with minimal overhead. -* -* @param arr - input array -* @param shape - desired shape -* @throws input array cannot have more dimensions than the desired shape -* @throws input array dimension sizes must be `1` or equal to the corresponding dimension in the provided shape -* @throws input array and desired shape must be broadcast compatible -* @returns broadcasted array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -*/ -declare function maybeBroadcastArray( arr: ndarray, shape: ArrayLike ): ndarray; - - -// EXPORTS // - -export = maybeBroadcastArray; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 7290520..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.2-esm/index.mjs";function e(e,s){var n,a,d;if(a=s.length,(n=t(e,!1)).length===a){for(d=0;d\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArray;\n"],"names":["maybeBroadcastArray","arr","shape","sh","N","i","length","getShape","broadcast"],"mappings":";;oMAqFA,SAASA,EAAqBC,EAAKC,GAClC,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAMI,QACVH,EAAKI,EAAUN,GAAK,IAGZK,SAAWF,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,KAAQH,EAAOG,GAEvB,OAAOG,EAAWP,EAAKC,GAGzB,OAAOD,CACP,CAED,OAAOO,EAAWP,EAAKC,EACxB"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index a9abfed..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From af9429ff6a8519e1060e878af96aa762b53dd4b4 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Sep 2024 12:37:07 +0000 Subject: [PATCH 098/119] 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 | 149 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 49 +- SECURITY.md | 5 - benchmark/benchmark.js | 290 -- benchmark/benchmark.ndims.js | 110 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 68 - docs/types/test.ts | 94 - examples/index.js | 45 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 68 - lib/main.js | 112 - package.json | 64 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 514 --- 44 files changed, 4871 insertions(+), 4826 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/benchmark.ndims.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (97%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/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 2cddb62..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-09-01T06:12:23.229Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 740d5ce..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/maybe-broadcast-array) 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 4fadc31..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/maybe-broadcast-array) 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 31edc84..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: '45 9 * * 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 + + ```
@@ -173,7 +164,7 @@ for ( i = 0; i < N; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -236,11 +227,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-maybe-broadcast-array/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor +[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor/tree/esm -[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes +[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm
diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index ba5f734..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,290 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var ndarrayBase = require( '@stdlib/ndarray-base-ctor' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArray = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::base_ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::base_ndarray,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( out.shape[ 0 ] !== shape[ 0 ] ) { - b.fail( 'unexpected result' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.ndims.js b/benchmark/benchmark.ndims.js deleted file mode 100644 index 739b74c..0000000 --- a/benchmark/benchmark.ndims.js +++ /dev/null @@ -1,110 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var array = require( '@stdlib/ndarray-array' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} ndims - number of dimensions to which to broadcast -* @returns {Function} benchmark function -*/ -function createBenchmark( ndims ) { - var shape; - var sh; - var x; - var i; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - sh = x.shape; - - shape = []; - for ( i = 0; i < ndims; i++ ) { - shape.push( 0 ); - } - for ( i = ndims; i >= 1; i-- ) { - if ( i > sh.length ) { - shape[ ndims-i ] = 5; - } else { - shape[ ndims-i ] = sh[ i-1 ]; - } - } - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( x, shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var min; - var max; - var f; - var i; - - min = 2; - max = 10; - - for ( i = min; i <= max; i++ ) { - f = createBenchmark( i ); - bench( pkg+'::ndarray,2d:from_ndims=2,to_ndims='+i, f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index e45b5c4..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/maybe-broadcast-array" -%% click B href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/maybe-broadcast-array -[production-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 71859ce..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import maybeBroadcastArray from '../docs/types/index'; -export = maybeBroadcastArray; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 4b04e84..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var o=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var s=o(function(l,n){ -var u=require('@stdlib/ndarray-base-broadcast-array/dist'),v=require('@stdlib/ndarray-base-shape/dist');function c(e,r){var i,a,t;if(a=r.length,i=v(e,!1),i.length===a){for(t=0;t\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nmodule.exports = maybeBroadcastArray;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape.\n*\n* @module @stdlib/ndarray-base-maybe-broadcast-array\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var maybeBroadcastArray = require( '@stdlib/ndarray-base-maybe-broadcast-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAY,QAAS,sCAAuC,EAC5DC,EAAW,QAAS,4BAA6B,EA8DrD,SAASC,EAAqBC,EAAKC,EAAQ,CAC1C,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAM,OACVC,EAAKJ,EAAUE,EAAK,EAAM,EAGrBE,EAAG,SAAWC,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,CAAE,IAAMH,EAAOG,CAAE,EAEzB,OAAOP,EAAWG,EAAKC,CAAM,EAG/B,OAAOD,CACR,CAEA,OAAOH,EAAWG,EAAKC,CAAM,CAC9B,CAKAL,EAAO,QAAUG,ICjDjB,IAAIM,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "broadcast", "getShape", "maybeBroadcastArray", "arr", "shape", "sh", "N", "i", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 01ecba8..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,68 +0,0 @@ - -{{alias}}( arr, shape ) - Broadcasts an ndarray to a specified shape if and only if the specified - shape differs from the provided ndarray's shape. - - If a provided ndarray has the same shape as the specified shape, the - function returns the provided ndarray. - - If a provided ndarray has a different (broadcast compatible) shape than the - specified shape, the function returns a new (base) ndarray view of the - provided ndarray's data. The view is typically **not** contiguous. As more - than one element of a returned view may refer to the same memory location, - writing to the view may affect multiple elements. If you need to write to - the returned array, copy the array before performing operations which may - mutate elements. - - A returned array view is a "base" ndarray, and, thus, a returned array view - does not perform bounds checking or afford any of the guarantees of the non- - base ndarray constructor. The primary intent of this function is to - broadcast an ndarray-like object within internal implementations and to do - so with minimal overhead. - - The function throws an error if a provided ndarray is incompatible with a - provided shape. - - Parameters - ---------- - arr: ndarray - Input array. - - shape: ArrayLikeObject - Desired shape. - - Returns - ------- - out: ndarray - Broadcasted array. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > var sh = x.shape - [ 2, 2 ] - > var y = {{alias}}( x, [ 3, 2, 2 ] ) - - > sh = y.shape - [ 3, 2, 2 ] - > var v = y.get( 0, 0, 0 ) - 1 - > v = y.get( 0, 0, 1 ) - 2 - > v = y.get( 0, 1, 0 ) - 3 - > v = y.get( 0, 1, 1 ) - 4 - > v = y.get( 1, 0, 0 ) - 1 - > v = y.get( 1, 1, 0 ) - 3 - > v = y.get( 2, 0, 0 ) - 1 - > v = y.get( 2, 1, 1 ) - 4 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index d7a1a62..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,94 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ndarray } from '@stdlib/types/ndarray'; -import maybeBroadcastArray = require( './index' ); - -/** -* Mock function to create an ndarray-like object. -* -* @return ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns an ndarray... -{ - const x = array(); - - maybeBroadcastArray( x, [ 2, 2, 2 ] ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is not provided a first argument which is an ndarray... -{ - maybeBroadcastArray( '5', [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( 5, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( true, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( false, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( null, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( {}, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( [ '5' ], [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( ( x: number ): number => x, [ 2, 2, 2 ] ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a second argument which is an array-like object containing numbers... -{ - const x = array(); - - maybeBroadcastArray( x, '5' ); // $ExpectError - maybeBroadcastArray( x, 5 ); // $ExpectError - maybeBroadcastArray( x, true ); // $ExpectError - maybeBroadcastArray( x, false ); // $ExpectError - maybeBroadcastArray( x, null ); // $ExpectError - maybeBroadcastArray( x, {} ); // $ExpectError - maybeBroadcastArray( x, [ '5' ] ); // $ExpectError - maybeBroadcastArray( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - - maybeBroadcastArray(); // $ExpectError - maybeBroadcastArray( x ); // $ExpectError - maybeBroadcastArray( x, [ 1, 2, 3 ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index e787d6e..0000000 --- a/examples/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 array = require( '@stdlib/ndarray-array' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var maybeBroadcastArray = require( './../lib' ); - -// Create a 2x2 array: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -// returns - -// Broadcast the array to 3x2x2: -var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -// returns - -// Retrieve the shape: -var sh = y.shape; -// returns [ 3, 2, 2 ] - -// Retrieve the number of elements: -var N = numel( sh ); - -// Loop through the array elements... -var i; -for ( i = 0; i < N; i++ ) { - console.log( 'Y[%s] = %d', ind2sub( sh, i ).join( ', ' ), y.iget( i ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 97% rename from docs/types/index.d.ts rename to index.d.ts index f354818..97640ae 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..7290520 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.2-esm/index.mjs";function e(e,s){var n,a,d;if(a=s.length,(n=t(e,!1)).length===a){for(d=0;d\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArray;\n"],"names":["maybeBroadcastArray","arr","shape","sh","N","i","length","getShape","broadcast"],"mappings":";;oMAqFA,SAASA,EAAqBC,EAAKC,GAClC,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAMI,QACVH,EAAKI,EAAUN,GAAK,IAGZK,SAAWF,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,KAAQH,EAAOG,GAEvB,OAAOG,EAAWP,EAAKC,GAGzB,OAAOD,CACP,CAED,OAAOO,EAAWP,EAAKC,EACxB"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 834e930..0000000 --- a/lib/index.js +++ /dev/null @@ -1,68 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* @module @stdlib/ndarray-base-maybe-broadcast-array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var maybeBroadcastArray = require( '@stdlib/ndarray-base-maybe-broadcast-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -*/ - -// 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 e59ca1d..0000000 --- a/lib/main.js +++ /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. -*/ - -'use strict'; - -// MODULES // - -var broadcast = require( '@stdlib/ndarray-base-broadcast-array' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); - - -// MAIN // - -/** -* Broadcasts an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* ## Notes -* -* - If a provided ndarray has the same shape as the specified shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the specified shape, the function returns a new (base) ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to the view may affect multiple elements. If you need to write to the returned array, copy the array before performing operations which may mutate elements. -* -* @param {ndarray} arr - input array -* @param {NonNegativeIntegerArray} shape - desired shape -* @throws {Error} input array cannot have more dimensions than the desired shape -* @throws {Error} input array dimension sizes must be `1` or equal to the corresponding dimension in the provided shape -* @throws {Error} input array and desired shape must be broadcast compatible -* @returns {ndarray} broadcasted array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var y = maybeBroadcastArray( x, [ 3, 2 ] ); -* // throws -*/ -function maybeBroadcastArray( arr, shape ) { - var sh; - var N; - var i; - - N = shape.length; - sh = getShape( arr, false ); - - // Check whether we need to broadcast the input array... - if ( sh.length === N ) { - for ( i = 0; i < N; i++ ) { - // Check whether dimensions match... - if ( sh[ i ] !== shape[ i ] ) { - // We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape... - return broadcast( arr, shape ); - } - } - return arr; - } - // If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape... - return broadcast( arr, shape ); -} - - -// EXPORTS // - -module.exports = maybeBroadcastArray; diff --git a/package.json b/package.json index 89af0b4..489e5cf 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.3", "description": "Broadcast an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's 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", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-base-broadcast-array": "^0.2.2", - "@stdlib/ndarray-base-shape": "^0.2.2", - "@stdlib/types": "^0.4.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-ctor": "^0.2.2", - "@stdlib/ndarray-ind2sub": "^0.2.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -86,9 +29,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..a9abfed --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 7e8e63f..0000000 --- a/test/test.js +++ /dev/null @@ -1,514 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 array = require( '@stdlib/ndarray-array' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var maybeBroadcastArray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof maybeBroadcastArray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a desired shape which has fewer dimensions than the input array', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 ] - }); - - values = [ - [], - [ 2 ], - [ 2, 2 ], - [ 2, 2, 2 ], - [ 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2, 2, 2 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided a shape with '+values[ i ].length+' dimension' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape having a dimension whose size is less than the corresponding dimension in the input array', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 10, 1 ], - [ 10, 10, 2 ], - [ 10, 10, 9 ], - [ 10, 1, 10 ], - [ 10, 2, 10 ], - [ 10, 9, 10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape and an input array shape which are broadcast-incompatible', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 20, 10 ], - [ 10, 10, 100 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function returns a "base" ndarray instance', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = maybeBroadcastArray( x, [ 2, 2, 2 ] ); - - t.notEqual( y, x, 'returns new instance' ); - t.strictEqual( y instanceof ndarray, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view over the input array data buffer', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = maybeBroadcastArray( x, [ 2, 2, 2 ] ); - - t.strictEqual( y.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; strides)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, -1 ], 3, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; strides)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, 1 ], 2, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; non-contiguous)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ 4, 2 ], 1, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 5 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 7 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (column-major)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'column-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (same shape)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2, 2 ], - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - // Should return the same instance: - t.strictEqual( y, x, 'returns expected value' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 1, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 1, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (same number of dimensions)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1, 2 ], - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (singleton dimension)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (singleton dimension)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 1, 2 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (0-dimensional array)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1 ]; - x = ndarray( 'generic', data, [], [ 0 ], 0, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); From 5b72249215a0b96ee6fd13060525095116eb2b58 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 28 Sep 2024 21:23:14 +0000 Subject: [PATCH 099/119] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 6c09d61..89af0b4 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,8 @@ "dependencies": { "@stdlib/ndarray-base-broadcast-array": "^0.2.2", "@stdlib/ndarray-base-shape": "^0.2.2", - "@stdlib/types": "^0.4.1" + "@stdlib/types": "^0.4.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, "devDependencies": { "@stdlib/array-float64": "^0.2.2", @@ -90,4 +91,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From 02ba90c35ed39c2f5c92db90dad7a8ed92fffb83 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 28 Sep 2024 21:36:24 +0000 Subject: [PATCH 100/119] Remove files --- index.d.ts | 81 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4928 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 97640ae..0000000 --- a/index.d.ts +++ /dev/null @@ -1,81 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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'; -import { ndarray } from '@stdlib/types/ndarray'; - -/** -* Broadcasts an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* ## Notes -* -* - The function throws an error if a provided ndarray is incompatible with a provided shape. -* - If a provided ndarray has the same shape as the specified shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the specified shape, the function returns a new (base) ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to the view may affect multiple elements. If you need to write to the returned array, copy the array before performing operations which may mutate elements. -* - A returned array view is a "base" ndarray, and, thus, a returned array view does not perform bounds checking or afford any of the guarantees of the non-base ndarray constructor. The primary intent of this function is to broadcast an ndarray-like object within internal implementations and to do so with minimal overhead. -* -* @param arr - input array -* @param shape - desired shape -* @throws input array cannot have more dimensions than the desired shape -* @throws input array dimension sizes must be `1` or equal to the corresponding dimension in the provided shape -* @throws input array and desired shape must be broadcast compatible -* @returns broadcasted array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -*/ -declare function maybeBroadcastArray( arr: ndarray, shape: ArrayLike ): ndarray; - - -// EXPORTS // - -export = maybeBroadcastArray; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 7290520..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.2-esm/index.mjs";function e(e,s){var n,a,d;if(a=s.length,(n=t(e,!1)).length===a){for(d=0;d\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArray;\n"],"names":["maybeBroadcastArray","arr","shape","sh","N","i","length","getShape","broadcast"],"mappings":";;oMAqFA,SAASA,EAAqBC,EAAKC,GAClC,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAMI,QACVH,EAAKI,EAAUN,GAAK,IAGZK,SAAWF,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,KAAQH,EAAOG,GAEvB,OAAOG,EAAWP,EAAKC,GAGzB,OAAOD,CACP,CAED,OAAOO,EAAWP,EAAKC,EACxB"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index a9abfed..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From c9eb54a423812d58afa9fb08090d3a7ecc07ebb2 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 28 Sep 2024 21:36:46 +0000 Subject: [PATCH 101/119] 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 | 183 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 49 +- SECURITY.md | 5 - benchmark/benchmark.js | 290 -- benchmark/benchmark.ndims.js | 110 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 68 - docs/types/test.ts | 94 - examples/index.js | 45 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 68 - lib/main.js | 112 - package.json | 64 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 514 --- 43 files changed, 4871 insertions(+), 4859 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/benchmark.ndims.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (97%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/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 740d5ce..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/maybe-broadcast-array) 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 4fadc31..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/maybe-broadcast-array) 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 31edc84..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: '45 9 * * 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 + + ```
@@ -173,7 +164,7 @@ for ( i = 0; i < N; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -236,11 +227,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-maybe-broadcast-array/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor +[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor/tree/esm -[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes +[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm
diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index ba5f734..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,290 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var ndarrayBase = require( '@stdlib/ndarray-base-ctor' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArray = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::base_ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::base_ndarray,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( out.shape[ 0 ] !== shape[ 0 ] ) { - b.fail( 'unexpected result' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.ndims.js b/benchmark/benchmark.ndims.js deleted file mode 100644 index 739b74c..0000000 --- a/benchmark/benchmark.ndims.js +++ /dev/null @@ -1,110 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var array = require( '@stdlib/ndarray-array' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} ndims - number of dimensions to which to broadcast -* @returns {Function} benchmark function -*/ -function createBenchmark( ndims ) { - var shape; - var sh; - var x; - var i; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - sh = x.shape; - - shape = []; - for ( i = 0; i < ndims; i++ ) { - shape.push( 0 ); - } - for ( i = ndims; i >= 1; i-- ) { - if ( i > sh.length ) { - shape[ ndims-i ] = 5; - } else { - shape[ ndims-i ] = sh[ i-1 ]; - } - } - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( x, shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var min; - var max; - var f; - var i; - - min = 2; - max = 10; - - for ( i = min; i <= max; i++ ) { - f = createBenchmark( i ); - bench( pkg+'::ndarray,2d:from_ndims=2,to_ndims='+i, f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index e45b5c4..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/maybe-broadcast-array" -%% click B href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/maybe-broadcast-array -[production-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 71859ce..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import maybeBroadcastArray from '../docs/types/index'; -export = maybeBroadcastArray; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 4b04e84..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var o=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var s=o(function(l,n){ -var u=require('@stdlib/ndarray-base-broadcast-array/dist'),v=require('@stdlib/ndarray-base-shape/dist');function c(e,r){var i,a,t;if(a=r.length,i=v(e,!1),i.length===a){for(t=0;t\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nmodule.exports = maybeBroadcastArray;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape.\n*\n* @module @stdlib/ndarray-base-maybe-broadcast-array\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var maybeBroadcastArray = require( '@stdlib/ndarray-base-maybe-broadcast-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAY,QAAS,sCAAuC,EAC5DC,EAAW,QAAS,4BAA6B,EA8DrD,SAASC,EAAqBC,EAAKC,EAAQ,CAC1C,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAM,OACVC,EAAKJ,EAAUE,EAAK,EAAM,EAGrBE,EAAG,SAAWC,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,CAAE,IAAMH,EAAOG,CAAE,EAEzB,OAAOP,EAAWG,EAAKC,CAAM,EAG/B,OAAOD,CACR,CAEA,OAAOH,EAAWG,EAAKC,CAAM,CAC9B,CAKAL,EAAO,QAAUG,ICjDjB,IAAIM,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "broadcast", "getShape", "maybeBroadcastArray", "arr", "shape", "sh", "N", "i", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 01ecba8..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,68 +0,0 @@ - -{{alias}}( arr, shape ) - Broadcasts an ndarray to a specified shape if and only if the specified - shape differs from the provided ndarray's shape. - - If a provided ndarray has the same shape as the specified shape, the - function returns the provided ndarray. - - If a provided ndarray has a different (broadcast compatible) shape than the - specified shape, the function returns a new (base) ndarray view of the - provided ndarray's data. The view is typically **not** contiguous. As more - than one element of a returned view may refer to the same memory location, - writing to the view may affect multiple elements. If you need to write to - the returned array, copy the array before performing operations which may - mutate elements. - - A returned array view is a "base" ndarray, and, thus, a returned array view - does not perform bounds checking or afford any of the guarantees of the non- - base ndarray constructor. The primary intent of this function is to - broadcast an ndarray-like object within internal implementations and to do - so with minimal overhead. - - The function throws an error if a provided ndarray is incompatible with a - provided shape. - - Parameters - ---------- - arr: ndarray - Input array. - - shape: ArrayLikeObject - Desired shape. - - Returns - ------- - out: ndarray - Broadcasted array. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > var sh = x.shape - [ 2, 2 ] - > var y = {{alias}}( x, [ 3, 2, 2 ] ) - - > sh = y.shape - [ 3, 2, 2 ] - > var v = y.get( 0, 0, 0 ) - 1 - > v = y.get( 0, 0, 1 ) - 2 - > v = y.get( 0, 1, 0 ) - 3 - > v = y.get( 0, 1, 1 ) - 4 - > v = y.get( 1, 0, 0 ) - 1 - > v = y.get( 1, 1, 0 ) - 3 - > v = y.get( 2, 0, 0 ) - 1 - > v = y.get( 2, 1, 1 ) - 4 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 8dc469f..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,94 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ndarray } from '@stdlib/types/ndarray'; -import maybeBroadcastArray = require( './index' ); - -/** -* Mock function to create an ndarray-like object. -* -* @returns ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns an ndarray... -{ - const x = array(); - - maybeBroadcastArray( x, [ 2, 2, 2 ] ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is not provided a first argument which is an ndarray... -{ - maybeBroadcastArray( '5', [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( 5, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( true, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( false, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( null, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( {}, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( [ '5' ], [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( ( x: number ): number => x, [ 2, 2, 2 ] ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a second argument which is an array-like object containing numbers... -{ - const x = array(); - - maybeBroadcastArray( x, '5' ); // $ExpectError - maybeBroadcastArray( x, 5 ); // $ExpectError - maybeBroadcastArray( x, true ); // $ExpectError - maybeBroadcastArray( x, false ); // $ExpectError - maybeBroadcastArray( x, null ); // $ExpectError - maybeBroadcastArray( x, {} ); // $ExpectError - maybeBroadcastArray( x, [ '5' ] ); // $ExpectError - maybeBroadcastArray( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - - maybeBroadcastArray(); // $ExpectError - maybeBroadcastArray( x ); // $ExpectError - maybeBroadcastArray( x, [ 1, 2, 3 ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index e787d6e..0000000 --- a/examples/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 array = require( '@stdlib/ndarray-array' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var maybeBroadcastArray = require( './../lib' ); - -// Create a 2x2 array: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -// returns - -// Broadcast the array to 3x2x2: -var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -// returns - -// Retrieve the shape: -var sh = y.shape; -// returns [ 3, 2, 2 ] - -// Retrieve the number of elements: -var N = numel( sh ); - -// Loop through the array elements... -var i; -for ( i = 0; i < N; i++ ) { - console.log( 'Y[%s] = %d', ind2sub( sh, i ).join( ', ' ), y.iget( i ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 97% rename from docs/types/index.d.ts rename to index.d.ts index f354818..97640ae 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..7290520 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.2-esm/index.mjs";function e(e,s){var n,a,d;if(a=s.length,(n=t(e,!1)).length===a){for(d=0;d\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArray;\n"],"names":["maybeBroadcastArray","arr","shape","sh","N","i","length","getShape","broadcast"],"mappings":";;oMAqFA,SAASA,EAAqBC,EAAKC,GAClC,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAMI,QACVH,EAAKI,EAAUN,GAAK,IAGZK,SAAWF,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,KAAQH,EAAOG,GAEvB,OAAOG,EAAWP,EAAKC,GAGzB,OAAOD,CACP,CAED,OAAOO,EAAWP,EAAKC,EACxB"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 834e930..0000000 --- a/lib/index.js +++ /dev/null @@ -1,68 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* @module @stdlib/ndarray-base-maybe-broadcast-array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var maybeBroadcastArray = require( '@stdlib/ndarray-base-maybe-broadcast-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -*/ - -// 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 e59ca1d..0000000 --- a/lib/main.js +++ /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. -*/ - -'use strict'; - -// MODULES // - -var broadcast = require( '@stdlib/ndarray-base-broadcast-array' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); - - -// MAIN // - -/** -* Broadcasts an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* ## Notes -* -* - If a provided ndarray has the same shape as the specified shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the specified shape, the function returns a new (base) ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to the view may affect multiple elements. If you need to write to the returned array, copy the array before performing operations which may mutate elements. -* -* @param {ndarray} arr - input array -* @param {NonNegativeIntegerArray} shape - desired shape -* @throws {Error} input array cannot have more dimensions than the desired shape -* @throws {Error} input array dimension sizes must be `1` or equal to the corresponding dimension in the provided shape -* @throws {Error} input array and desired shape must be broadcast compatible -* @returns {ndarray} broadcasted array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var y = maybeBroadcastArray( x, [ 3, 2 ] ); -* // throws -*/ -function maybeBroadcastArray( arr, shape ) { - var sh; - var N; - var i; - - N = shape.length; - sh = getShape( arr, false ); - - // Check whether we need to broadcast the input array... - if ( sh.length === N ) { - for ( i = 0; i < N; i++ ) { - // Check whether dimensions match... - if ( sh[ i ] !== shape[ i ] ) { - // We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape... - return broadcast( arr, shape ); - } - } - return arr; - } - // If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape... - return broadcast( arr, shape ); -} - - -// EXPORTS // - -module.exports = maybeBroadcastArray; diff --git a/package.json b/package.json index 89af0b4..489e5cf 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.3", "description": "Broadcast an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's 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", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-base-broadcast-array": "^0.2.2", - "@stdlib/ndarray-base-shape": "^0.2.2", - "@stdlib/types": "^0.4.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-ctor": "^0.2.2", - "@stdlib/ndarray-ind2sub": "^0.2.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -86,9 +29,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..a9abfed --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 7e8e63f..0000000 --- a/test/test.js +++ /dev/null @@ -1,514 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 array = require( '@stdlib/ndarray-array' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var maybeBroadcastArray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof maybeBroadcastArray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a desired shape which has fewer dimensions than the input array', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 ] - }); - - values = [ - [], - [ 2 ], - [ 2, 2 ], - [ 2, 2, 2 ], - [ 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2, 2, 2 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided a shape with '+values[ i ].length+' dimension' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape having a dimension whose size is less than the corresponding dimension in the input array', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 10, 1 ], - [ 10, 10, 2 ], - [ 10, 10, 9 ], - [ 10, 1, 10 ], - [ 10, 2, 10 ], - [ 10, 9, 10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape and an input array shape which are broadcast-incompatible', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 20, 10 ], - [ 10, 10, 100 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function returns a "base" ndarray instance', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = maybeBroadcastArray( x, [ 2, 2, 2 ] ); - - t.notEqual( y, x, 'returns new instance' ); - t.strictEqual( y instanceof ndarray, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view over the input array data buffer', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = maybeBroadcastArray( x, [ 2, 2, 2 ] ); - - t.strictEqual( y.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; strides)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, -1 ], 3, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; strides)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, 1 ], 2, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; non-contiguous)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ 4, 2 ], 1, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 5 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 7 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (column-major)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'column-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (same shape)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2, 2 ], - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - // Should return the same instance: - t.strictEqual( y, x, 'returns expected value' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 1, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 1, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (same number of dimensions)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1, 2 ], - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (singleton dimension)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (singleton dimension)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 1, 2 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (0-dimensional array)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1 ]; - x = ndarray( 'generic', data, [], [ 0 ], 0, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); From 944ace9e7ec12f9ab5fb6fbbf770b824c3851794 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Oct 2024 08:31:47 +0000 Subject: [PATCH 102/119] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 6c09d61..89af0b4 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,8 @@ "dependencies": { "@stdlib/ndarray-base-broadcast-array": "^0.2.2", "@stdlib/ndarray-base-shape": "^0.2.2", - "@stdlib/types": "^0.4.1" + "@stdlib/types": "^0.4.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, "devDependencies": { "@stdlib/array-float64": "^0.2.2", @@ -90,4 +91,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From d1119e27f0c859f82f71b0a30277d1a38f12957a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Oct 2024 13:12:29 +0000 Subject: [PATCH 103/119] Remove files --- index.d.ts | 81 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4928 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 97640ae..0000000 --- a/index.d.ts +++ /dev/null @@ -1,81 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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'; -import { ndarray } from '@stdlib/types/ndarray'; - -/** -* Broadcasts an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* ## Notes -* -* - The function throws an error if a provided ndarray is incompatible with a provided shape. -* - If a provided ndarray has the same shape as the specified shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the specified shape, the function returns a new (base) ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to the view may affect multiple elements. If you need to write to the returned array, copy the array before performing operations which may mutate elements. -* - A returned array view is a "base" ndarray, and, thus, a returned array view does not perform bounds checking or afford any of the guarantees of the non-base ndarray constructor. The primary intent of this function is to broadcast an ndarray-like object within internal implementations and to do so with minimal overhead. -* -* @param arr - input array -* @param shape - desired shape -* @throws input array cannot have more dimensions than the desired shape -* @throws input array dimension sizes must be `1` or equal to the corresponding dimension in the provided shape -* @throws input array and desired shape must be broadcast compatible -* @returns broadcasted array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -*/ -declare function maybeBroadcastArray( arr: ndarray, shape: ArrayLike ): ndarray; - - -// EXPORTS // - -export = maybeBroadcastArray; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 7290520..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.2-esm/index.mjs";function e(e,s){var n,a,d;if(a=s.length,(n=t(e,!1)).length===a){for(d=0;d\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArray;\n"],"names":["maybeBroadcastArray","arr","shape","sh","N","i","length","getShape","broadcast"],"mappings":";;oMAqFA,SAASA,EAAqBC,EAAKC,GAClC,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAMI,QACVH,EAAKI,EAAUN,GAAK,IAGZK,SAAWF,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,KAAQH,EAAOG,GAEvB,OAAOG,EAAWP,EAAKC,GAGzB,OAAOD,CACP,CAED,OAAOO,EAAWP,EAAKC,EACxB"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index a9abfed..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 99ce458d7d4d93902bfd1a36319476de61255313 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Oct 2024 13:12:46 +0000 Subject: [PATCH 104/119] 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 | 183 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 49 +- SECURITY.md | 5 - benchmark/benchmark.js | 290 -- benchmark/benchmark.ndims.js | 110 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 68 - docs/types/test.ts | 94 - examples/index.js | 45 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 68 - lib/main.js | 112 - package.json | 64 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 514 --- 44 files changed, 4871 insertions(+), 4860 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/benchmark.ndims.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (97%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/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 f25ffbc..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-10-01T06:24:37.303Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 740d5ce..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/maybe-broadcast-array) 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 4fadc31..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/maybe-broadcast-array) 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 31edc84..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: '45 9 * * 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 + + ```
@@ -173,7 +164,7 @@ for ( i = 0; i < N; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -236,11 +227,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-maybe-broadcast-array/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor +[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor/tree/esm -[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes +[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm
diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index ba5f734..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,290 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var ndarrayBase = require( '@stdlib/ndarray-base-ctor' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArray = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::base_ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::base_ndarray,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( out.shape[ 0 ] !== shape[ 0 ] ) { - b.fail( 'unexpected result' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.ndims.js b/benchmark/benchmark.ndims.js deleted file mode 100644 index 739b74c..0000000 --- a/benchmark/benchmark.ndims.js +++ /dev/null @@ -1,110 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var array = require( '@stdlib/ndarray-array' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} ndims - number of dimensions to which to broadcast -* @returns {Function} benchmark function -*/ -function createBenchmark( ndims ) { - var shape; - var sh; - var x; - var i; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - sh = x.shape; - - shape = []; - for ( i = 0; i < ndims; i++ ) { - shape.push( 0 ); - } - for ( i = ndims; i >= 1; i-- ) { - if ( i > sh.length ) { - shape[ ndims-i ] = 5; - } else { - shape[ ndims-i ] = sh[ i-1 ]; - } - } - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( x, shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var min; - var max; - var f; - var i; - - min = 2; - max = 10; - - for ( i = min; i <= max; i++ ) { - f = createBenchmark( i ); - bench( pkg+'::ndarray,2d:from_ndims=2,to_ndims='+i, f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index e45b5c4..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/maybe-broadcast-array" -%% click B href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/maybe-broadcast-array -[production-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 71859ce..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import maybeBroadcastArray from '../docs/types/index'; -export = maybeBroadcastArray; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 4b04e84..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var o=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var s=o(function(l,n){ -var u=require('@stdlib/ndarray-base-broadcast-array/dist'),v=require('@stdlib/ndarray-base-shape/dist');function c(e,r){var i,a,t;if(a=r.length,i=v(e,!1),i.length===a){for(t=0;t\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nmodule.exports = maybeBroadcastArray;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape.\n*\n* @module @stdlib/ndarray-base-maybe-broadcast-array\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var maybeBroadcastArray = require( '@stdlib/ndarray-base-maybe-broadcast-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAY,QAAS,sCAAuC,EAC5DC,EAAW,QAAS,4BAA6B,EA8DrD,SAASC,EAAqBC,EAAKC,EAAQ,CAC1C,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAM,OACVC,EAAKJ,EAAUE,EAAK,EAAM,EAGrBE,EAAG,SAAWC,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,CAAE,IAAMH,EAAOG,CAAE,EAEzB,OAAOP,EAAWG,EAAKC,CAAM,EAG/B,OAAOD,CACR,CAEA,OAAOH,EAAWG,EAAKC,CAAM,CAC9B,CAKAL,EAAO,QAAUG,ICjDjB,IAAIM,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "broadcast", "getShape", "maybeBroadcastArray", "arr", "shape", "sh", "N", "i", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 01ecba8..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,68 +0,0 @@ - -{{alias}}( arr, shape ) - Broadcasts an ndarray to a specified shape if and only if the specified - shape differs from the provided ndarray's shape. - - If a provided ndarray has the same shape as the specified shape, the - function returns the provided ndarray. - - If a provided ndarray has a different (broadcast compatible) shape than the - specified shape, the function returns a new (base) ndarray view of the - provided ndarray's data. The view is typically **not** contiguous. As more - than one element of a returned view may refer to the same memory location, - writing to the view may affect multiple elements. If you need to write to - the returned array, copy the array before performing operations which may - mutate elements. - - A returned array view is a "base" ndarray, and, thus, a returned array view - does not perform bounds checking or afford any of the guarantees of the non- - base ndarray constructor. The primary intent of this function is to - broadcast an ndarray-like object within internal implementations and to do - so with minimal overhead. - - The function throws an error if a provided ndarray is incompatible with a - provided shape. - - Parameters - ---------- - arr: ndarray - Input array. - - shape: ArrayLikeObject - Desired shape. - - Returns - ------- - out: ndarray - Broadcasted array. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > var sh = x.shape - [ 2, 2 ] - > var y = {{alias}}( x, [ 3, 2, 2 ] ) - - > sh = y.shape - [ 3, 2, 2 ] - > var v = y.get( 0, 0, 0 ) - 1 - > v = y.get( 0, 0, 1 ) - 2 - > v = y.get( 0, 1, 0 ) - 3 - > v = y.get( 0, 1, 1 ) - 4 - > v = y.get( 1, 0, 0 ) - 1 - > v = y.get( 1, 1, 0 ) - 3 - > v = y.get( 2, 0, 0 ) - 1 - > v = y.get( 2, 1, 1 ) - 4 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 8dc469f..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,94 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ndarray } from '@stdlib/types/ndarray'; -import maybeBroadcastArray = require( './index' ); - -/** -* Mock function to create an ndarray-like object. -* -* @returns ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns an ndarray... -{ - const x = array(); - - maybeBroadcastArray( x, [ 2, 2, 2 ] ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is not provided a first argument which is an ndarray... -{ - maybeBroadcastArray( '5', [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( 5, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( true, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( false, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( null, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( {}, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( [ '5' ], [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( ( x: number ): number => x, [ 2, 2, 2 ] ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a second argument which is an array-like object containing numbers... -{ - const x = array(); - - maybeBroadcastArray( x, '5' ); // $ExpectError - maybeBroadcastArray( x, 5 ); // $ExpectError - maybeBroadcastArray( x, true ); // $ExpectError - maybeBroadcastArray( x, false ); // $ExpectError - maybeBroadcastArray( x, null ); // $ExpectError - maybeBroadcastArray( x, {} ); // $ExpectError - maybeBroadcastArray( x, [ '5' ] ); // $ExpectError - maybeBroadcastArray( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - - maybeBroadcastArray(); // $ExpectError - maybeBroadcastArray( x ); // $ExpectError - maybeBroadcastArray( x, [ 1, 2, 3 ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index e787d6e..0000000 --- a/examples/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 array = require( '@stdlib/ndarray-array' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var maybeBroadcastArray = require( './../lib' ); - -// Create a 2x2 array: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -// returns - -// Broadcast the array to 3x2x2: -var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -// returns - -// Retrieve the shape: -var sh = y.shape; -// returns [ 3, 2, 2 ] - -// Retrieve the number of elements: -var N = numel( sh ); - -// Loop through the array elements... -var i; -for ( i = 0; i < N; i++ ) { - console.log( 'Y[%s] = %d', ind2sub( sh, i ).join( ', ' ), y.iget( i ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 97% rename from docs/types/index.d.ts rename to index.d.ts index f354818..97640ae 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..7290520 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.2-esm/index.mjs";function e(e,s){var n,a,d;if(a=s.length,(n=t(e,!1)).length===a){for(d=0;d\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArray;\n"],"names":["maybeBroadcastArray","arr","shape","sh","N","i","length","getShape","broadcast"],"mappings":";;oMAqFA,SAASA,EAAqBC,EAAKC,GAClC,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAMI,QACVH,EAAKI,EAAUN,GAAK,IAGZK,SAAWF,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,KAAQH,EAAOG,GAEvB,OAAOG,EAAWP,EAAKC,GAGzB,OAAOD,CACP,CAED,OAAOO,EAAWP,EAAKC,EACxB"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 834e930..0000000 --- a/lib/index.js +++ /dev/null @@ -1,68 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* @module @stdlib/ndarray-base-maybe-broadcast-array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var maybeBroadcastArray = require( '@stdlib/ndarray-base-maybe-broadcast-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -*/ - -// 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 e59ca1d..0000000 --- a/lib/main.js +++ /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. -*/ - -'use strict'; - -// MODULES // - -var broadcast = require( '@stdlib/ndarray-base-broadcast-array' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); - - -// MAIN // - -/** -* Broadcasts an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* ## Notes -* -* - If a provided ndarray has the same shape as the specified shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the specified shape, the function returns a new (base) ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to the view may affect multiple elements. If you need to write to the returned array, copy the array before performing operations which may mutate elements. -* -* @param {ndarray} arr - input array -* @param {NonNegativeIntegerArray} shape - desired shape -* @throws {Error} input array cannot have more dimensions than the desired shape -* @throws {Error} input array dimension sizes must be `1` or equal to the corresponding dimension in the provided shape -* @throws {Error} input array and desired shape must be broadcast compatible -* @returns {ndarray} broadcasted array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var y = maybeBroadcastArray( x, [ 3, 2 ] ); -* // throws -*/ -function maybeBroadcastArray( arr, shape ) { - var sh; - var N; - var i; - - N = shape.length; - sh = getShape( arr, false ); - - // Check whether we need to broadcast the input array... - if ( sh.length === N ) { - for ( i = 0; i < N; i++ ) { - // Check whether dimensions match... - if ( sh[ i ] !== shape[ i ] ) { - // We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape... - return broadcast( arr, shape ); - } - } - return arr; - } - // If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape... - return broadcast( arr, shape ); -} - - -// EXPORTS // - -module.exports = maybeBroadcastArray; diff --git a/package.json b/package.json index 89af0b4..489e5cf 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.3", "description": "Broadcast an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's 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", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-base-broadcast-array": "^0.2.2", - "@stdlib/ndarray-base-shape": "^0.2.2", - "@stdlib/types": "^0.4.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-ctor": "^0.2.2", - "@stdlib/ndarray-ind2sub": "^0.2.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -86,9 +29,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..a9abfed --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 7e8e63f..0000000 --- a/test/test.js +++ /dev/null @@ -1,514 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 array = require( '@stdlib/ndarray-array' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var maybeBroadcastArray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof maybeBroadcastArray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a desired shape which has fewer dimensions than the input array', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 ] - }); - - values = [ - [], - [ 2 ], - [ 2, 2 ], - [ 2, 2, 2 ], - [ 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2, 2, 2 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided a shape with '+values[ i ].length+' dimension' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape having a dimension whose size is less than the corresponding dimension in the input array', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 10, 1 ], - [ 10, 10, 2 ], - [ 10, 10, 9 ], - [ 10, 1, 10 ], - [ 10, 2, 10 ], - [ 10, 9, 10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape and an input array shape which are broadcast-incompatible', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 20, 10 ], - [ 10, 10, 100 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function returns a "base" ndarray instance', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = maybeBroadcastArray( x, [ 2, 2, 2 ] ); - - t.notEqual( y, x, 'returns new instance' ); - t.strictEqual( y instanceof ndarray, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view over the input array data buffer', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = maybeBroadcastArray( x, [ 2, 2, 2 ] ); - - t.strictEqual( y.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; strides)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, -1 ], 3, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; strides)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, 1 ], 2, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; non-contiguous)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ 4, 2 ], 1, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 5 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 7 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (column-major)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'column-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (same shape)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2, 2 ], - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - // Should return the same instance: - t.strictEqual( y, x, 'returns expected value' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 1, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 1, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (same number of dimensions)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1, 2 ], - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (singleton dimension)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (singleton dimension)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 1, 2 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (0-dimensional array)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1 ]; - x = ndarray( 'generic', data, [], [ 0 ], 0, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); From 8c7560bcbae0fcf47b95a4953f79ac27dca5074a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Nov 2024 08:19:25 +0000 Subject: [PATCH 105/119] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 6c09d61..89af0b4 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,8 @@ "dependencies": { "@stdlib/ndarray-base-broadcast-array": "^0.2.2", "@stdlib/ndarray-base-shape": "^0.2.2", - "@stdlib/types": "^0.4.1" + "@stdlib/types": "^0.4.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, "devDependencies": { "@stdlib/array-float64": "^0.2.2", @@ -90,4 +91,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From 82650bf588f2eb49d76e5efd8ec86fba7a78677f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Nov 2024 12:15:35 +0000 Subject: [PATCH 106/119] Remove files --- index.d.ts | 81 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4928 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 97640ae..0000000 --- a/index.d.ts +++ /dev/null @@ -1,81 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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'; -import { ndarray } from '@stdlib/types/ndarray'; - -/** -* Broadcasts an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* ## Notes -* -* - The function throws an error if a provided ndarray is incompatible with a provided shape. -* - If a provided ndarray has the same shape as the specified shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the specified shape, the function returns a new (base) ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to the view may affect multiple elements. If you need to write to the returned array, copy the array before performing operations which may mutate elements. -* - A returned array view is a "base" ndarray, and, thus, a returned array view does not perform bounds checking or afford any of the guarantees of the non-base ndarray constructor. The primary intent of this function is to broadcast an ndarray-like object within internal implementations and to do so with minimal overhead. -* -* @param arr - input array -* @param shape - desired shape -* @throws input array cannot have more dimensions than the desired shape -* @throws input array dimension sizes must be `1` or equal to the corresponding dimension in the provided shape -* @throws input array and desired shape must be broadcast compatible -* @returns broadcasted array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -*/ -declare function maybeBroadcastArray( arr: ndarray, shape: ArrayLike ): ndarray; - - -// EXPORTS // - -export = maybeBroadcastArray; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 7290520..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.2-esm/index.mjs";function e(e,s){var n,a,d;if(a=s.length,(n=t(e,!1)).length===a){for(d=0;d\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArray;\n"],"names":["maybeBroadcastArray","arr","shape","sh","N","i","length","getShape","broadcast"],"mappings":";;oMAqFA,SAASA,EAAqBC,EAAKC,GAClC,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAMI,QACVH,EAAKI,EAAUN,GAAK,IAGZK,SAAWF,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,KAAQH,EAAOG,GAEvB,OAAOG,EAAWP,EAAKC,GAGzB,OAAOD,CACP,CAED,OAAOO,EAAWP,EAAKC,EACxB"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index a9abfed..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 2c833634cd3bd822895ac3f3b372ccb2f48d1090 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Nov 2024 12:15:50 +0000 Subject: [PATCH 107/119] 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 | 183 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 49 +- SECURITY.md | 5 - benchmark/benchmark.js | 290 -- benchmark/benchmark.ndims.js | 110 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 68 - docs/types/test.ts | 94 - examples/index.js | 45 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 68 - lib/main.js | 112 - package.json | 64 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 514 --- 44 files changed, 4871 insertions(+), 4860 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/benchmark.ndims.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (97%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/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 c90fa85..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-11-01T06:27:43.368Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 740d5ce..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/maybe-broadcast-array) 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 4fadc31..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/maybe-broadcast-array) 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 31edc84..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: '45 9 * * 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 + + ```
@@ -173,7 +164,7 @@ for ( i = 0; i < N; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -236,11 +227,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-maybe-broadcast-array/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor +[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor/tree/esm -[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes +[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm
diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index ba5f734..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,290 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var ndarrayBase = require( '@stdlib/ndarray-base-ctor' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArray = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::base_ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::base_ndarray,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( out.shape[ 0 ] !== shape[ 0 ] ) { - b.fail( 'unexpected result' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.ndims.js b/benchmark/benchmark.ndims.js deleted file mode 100644 index 739b74c..0000000 --- a/benchmark/benchmark.ndims.js +++ /dev/null @@ -1,110 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var array = require( '@stdlib/ndarray-array' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} ndims - number of dimensions to which to broadcast -* @returns {Function} benchmark function -*/ -function createBenchmark( ndims ) { - var shape; - var sh; - var x; - var i; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - sh = x.shape; - - shape = []; - for ( i = 0; i < ndims; i++ ) { - shape.push( 0 ); - } - for ( i = ndims; i >= 1; i-- ) { - if ( i > sh.length ) { - shape[ ndims-i ] = 5; - } else { - shape[ ndims-i ] = sh[ i-1 ]; - } - } - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( x, shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var min; - var max; - var f; - var i; - - min = 2; - max = 10; - - for ( i = min; i <= max; i++ ) { - f = createBenchmark( i ); - bench( pkg+'::ndarray,2d:from_ndims=2,to_ndims='+i, f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index e45b5c4..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/maybe-broadcast-array" -%% click B href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/maybe-broadcast-array -[production-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 71859ce..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import maybeBroadcastArray from '../docs/types/index'; -export = maybeBroadcastArray; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 4b04e84..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var o=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var s=o(function(l,n){ -var u=require('@stdlib/ndarray-base-broadcast-array/dist'),v=require('@stdlib/ndarray-base-shape/dist');function c(e,r){var i,a,t;if(a=r.length,i=v(e,!1),i.length===a){for(t=0;t\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nmodule.exports = maybeBroadcastArray;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape.\n*\n* @module @stdlib/ndarray-base-maybe-broadcast-array\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var maybeBroadcastArray = require( '@stdlib/ndarray-base-maybe-broadcast-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAY,QAAS,sCAAuC,EAC5DC,EAAW,QAAS,4BAA6B,EA8DrD,SAASC,EAAqBC,EAAKC,EAAQ,CAC1C,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAM,OACVC,EAAKJ,EAAUE,EAAK,EAAM,EAGrBE,EAAG,SAAWC,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,CAAE,IAAMH,EAAOG,CAAE,EAEzB,OAAOP,EAAWG,EAAKC,CAAM,EAG/B,OAAOD,CACR,CAEA,OAAOH,EAAWG,EAAKC,CAAM,CAC9B,CAKAL,EAAO,QAAUG,ICjDjB,IAAIM,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "broadcast", "getShape", "maybeBroadcastArray", "arr", "shape", "sh", "N", "i", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 01ecba8..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,68 +0,0 @@ - -{{alias}}( arr, shape ) - Broadcasts an ndarray to a specified shape if and only if the specified - shape differs from the provided ndarray's shape. - - If a provided ndarray has the same shape as the specified shape, the - function returns the provided ndarray. - - If a provided ndarray has a different (broadcast compatible) shape than the - specified shape, the function returns a new (base) ndarray view of the - provided ndarray's data. The view is typically **not** contiguous. As more - than one element of a returned view may refer to the same memory location, - writing to the view may affect multiple elements. If you need to write to - the returned array, copy the array before performing operations which may - mutate elements. - - A returned array view is a "base" ndarray, and, thus, a returned array view - does not perform bounds checking or afford any of the guarantees of the non- - base ndarray constructor. The primary intent of this function is to - broadcast an ndarray-like object within internal implementations and to do - so with minimal overhead. - - The function throws an error if a provided ndarray is incompatible with a - provided shape. - - Parameters - ---------- - arr: ndarray - Input array. - - shape: ArrayLikeObject - Desired shape. - - Returns - ------- - out: ndarray - Broadcasted array. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > var sh = x.shape - [ 2, 2 ] - > var y = {{alias}}( x, [ 3, 2, 2 ] ) - - > sh = y.shape - [ 3, 2, 2 ] - > var v = y.get( 0, 0, 0 ) - 1 - > v = y.get( 0, 0, 1 ) - 2 - > v = y.get( 0, 1, 0 ) - 3 - > v = y.get( 0, 1, 1 ) - 4 - > v = y.get( 1, 0, 0 ) - 1 - > v = y.get( 1, 1, 0 ) - 3 - > v = y.get( 2, 0, 0 ) - 1 - > v = y.get( 2, 1, 1 ) - 4 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 8dc469f..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,94 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ndarray } from '@stdlib/types/ndarray'; -import maybeBroadcastArray = require( './index' ); - -/** -* Mock function to create an ndarray-like object. -* -* @returns ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns an ndarray... -{ - const x = array(); - - maybeBroadcastArray( x, [ 2, 2, 2 ] ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is not provided a first argument which is an ndarray... -{ - maybeBroadcastArray( '5', [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( 5, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( true, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( false, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( null, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( {}, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( [ '5' ], [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( ( x: number ): number => x, [ 2, 2, 2 ] ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a second argument which is an array-like object containing numbers... -{ - const x = array(); - - maybeBroadcastArray( x, '5' ); // $ExpectError - maybeBroadcastArray( x, 5 ); // $ExpectError - maybeBroadcastArray( x, true ); // $ExpectError - maybeBroadcastArray( x, false ); // $ExpectError - maybeBroadcastArray( x, null ); // $ExpectError - maybeBroadcastArray( x, {} ); // $ExpectError - maybeBroadcastArray( x, [ '5' ] ); // $ExpectError - maybeBroadcastArray( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - - maybeBroadcastArray(); // $ExpectError - maybeBroadcastArray( x ); // $ExpectError - maybeBroadcastArray( x, [ 1, 2, 3 ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index e787d6e..0000000 --- a/examples/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 array = require( '@stdlib/ndarray-array' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var maybeBroadcastArray = require( './../lib' ); - -// Create a 2x2 array: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -// returns - -// Broadcast the array to 3x2x2: -var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -// returns - -// Retrieve the shape: -var sh = y.shape; -// returns [ 3, 2, 2 ] - -// Retrieve the number of elements: -var N = numel( sh ); - -// Loop through the array elements... -var i; -for ( i = 0; i < N; i++ ) { - console.log( 'Y[%s] = %d', ind2sub( sh, i ).join( ', ' ), y.iget( i ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 97% rename from docs/types/index.d.ts rename to index.d.ts index f354818..97640ae 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..7290520 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.2-esm/index.mjs";function e(e,s){var n,a,d;if(a=s.length,(n=t(e,!1)).length===a){for(d=0;d\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArray;\n"],"names":["maybeBroadcastArray","arr","shape","sh","N","i","length","getShape","broadcast"],"mappings":";;oMAqFA,SAASA,EAAqBC,EAAKC,GAClC,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAMI,QACVH,EAAKI,EAAUN,GAAK,IAGZK,SAAWF,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,KAAQH,EAAOG,GAEvB,OAAOG,EAAWP,EAAKC,GAGzB,OAAOD,CACP,CAED,OAAOO,EAAWP,EAAKC,EACxB"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 834e930..0000000 --- a/lib/index.js +++ /dev/null @@ -1,68 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* @module @stdlib/ndarray-base-maybe-broadcast-array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var maybeBroadcastArray = require( '@stdlib/ndarray-base-maybe-broadcast-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -*/ - -// 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 e59ca1d..0000000 --- a/lib/main.js +++ /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. -*/ - -'use strict'; - -// MODULES // - -var broadcast = require( '@stdlib/ndarray-base-broadcast-array' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); - - -// MAIN // - -/** -* Broadcasts an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* ## Notes -* -* - If a provided ndarray has the same shape as the specified shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the specified shape, the function returns a new (base) ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to the view may affect multiple elements. If you need to write to the returned array, copy the array before performing operations which may mutate elements. -* -* @param {ndarray} arr - input array -* @param {NonNegativeIntegerArray} shape - desired shape -* @throws {Error} input array cannot have more dimensions than the desired shape -* @throws {Error} input array dimension sizes must be `1` or equal to the corresponding dimension in the provided shape -* @throws {Error} input array and desired shape must be broadcast compatible -* @returns {ndarray} broadcasted array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var y = maybeBroadcastArray( x, [ 3, 2 ] ); -* // throws -*/ -function maybeBroadcastArray( arr, shape ) { - var sh; - var N; - var i; - - N = shape.length; - sh = getShape( arr, false ); - - // Check whether we need to broadcast the input array... - if ( sh.length === N ) { - for ( i = 0; i < N; i++ ) { - // Check whether dimensions match... - if ( sh[ i ] !== shape[ i ] ) { - // We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape... - return broadcast( arr, shape ); - } - } - return arr; - } - // If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape... - return broadcast( arr, shape ); -} - - -// EXPORTS // - -module.exports = maybeBroadcastArray; diff --git a/package.json b/package.json index 89af0b4..489e5cf 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.3", "description": "Broadcast an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's 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", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-base-broadcast-array": "^0.2.2", - "@stdlib/ndarray-base-shape": "^0.2.2", - "@stdlib/types": "^0.4.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-ctor": "^0.2.2", - "@stdlib/ndarray-ind2sub": "^0.2.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -86,9 +29,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..a9abfed --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 7e8e63f..0000000 --- a/test/test.js +++ /dev/null @@ -1,514 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 array = require( '@stdlib/ndarray-array' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var maybeBroadcastArray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof maybeBroadcastArray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a desired shape which has fewer dimensions than the input array', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 ] - }); - - values = [ - [], - [ 2 ], - [ 2, 2 ], - [ 2, 2, 2 ], - [ 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2, 2, 2 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided a shape with '+values[ i ].length+' dimension' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape having a dimension whose size is less than the corresponding dimension in the input array', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 10, 1 ], - [ 10, 10, 2 ], - [ 10, 10, 9 ], - [ 10, 1, 10 ], - [ 10, 2, 10 ], - [ 10, 9, 10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape and an input array shape which are broadcast-incompatible', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 20, 10 ], - [ 10, 10, 100 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function returns a "base" ndarray instance', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = maybeBroadcastArray( x, [ 2, 2, 2 ] ); - - t.notEqual( y, x, 'returns new instance' ); - t.strictEqual( y instanceof ndarray, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view over the input array data buffer', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = maybeBroadcastArray( x, [ 2, 2, 2 ] ); - - t.strictEqual( y.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; strides)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, -1 ], 3, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; strides)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, 1 ], 2, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; non-contiguous)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ 4, 2 ], 1, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 5 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 7 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (column-major)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'column-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (same shape)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2, 2 ], - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - // Should return the same instance: - t.strictEqual( y, x, 'returns expected value' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 1, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 1, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (same number of dimensions)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1, 2 ], - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (singleton dimension)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (singleton dimension)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 1, 2 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (0-dimensional array)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1 ]; - x = ndarray( 'generic', data, [], [ 0 ], 0, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); From aaa308f460e2ffb8bf840c5c93f414bdaa240202 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Dec 2024 08:35:16 +0000 Subject: [PATCH 108/119] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index a41389b..0909b3c 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,8 @@ "dependencies": { "@stdlib/ndarray-base-broadcast-array": "^0.2.2", "@stdlib/ndarray-base-shape": "^0.2.2", - "@stdlib/types": "^0.4.3" + "@stdlib/types": "^0.4.3", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, "devDependencies": { "@stdlib/array-float64": "^0.2.2", @@ -90,4 +91,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From dcbc6b5f274d7c07a5635a98b81e8db2d0ca6bfe Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Dec 2024 12:42:09 +0000 Subject: [PATCH 109/119] Remove files --- index.d.ts | 81 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4928 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 97640ae..0000000 --- a/index.d.ts +++ /dev/null @@ -1,81 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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'; -import { ndarray } from '@stdlib/types/ndarray'; - -/** -* Broadcasts an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* ## Notes -* -* - The function throws an error if a provided ndarray is incompatible with a provided shape. -* - If a provided ndarray has the same shape as the specified shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the specified shape, the function returns a new (base) ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to the view may affect multiple elements. If you need to write to the returned array, copy the array before performing operations which may mutate elements. -* - A returned array view is a "base" ndarray, and, thus, a returned array view does not perform bounds checking or afford any of the guarantees of the non-base ndarray constructor. The primary intent of this function is to broadcast an ndarray-like object within internal implementations and to do so with minimal overhead. -* -* @param arr - input array -* @param shape - desired shape -* @throws input array cannot have more dimensions than the desired shape -* @throws input array dimension sizes must be `1` or equal to the corresponding dimension in the provided shape -* @throws input array and desired shape must be broadcast compatible -* @returns broadcasted array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -*/ -declare function maybeBroadcastArray( arr: ndarray, shape: ArrayLike ): ndarray; - - -// EXPORTS // - -export = maybeBroadcastArray; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 7290520..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.2-esm/index.mjs";function e(e,s){var n,a,d;if(a=s.length,(n=t(e,!1)).length===a){for(d=0;d\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArray;\n"],"names":["maybeBroadcastArray","arr","shape","sh","N","i","length","getShape","broadcast"],"mappings":";;oMAqFA,SAASA,EAAqBC,EAAKC,GAClC,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAMI,QACVH,EAAKI,EAAUN,GAAK,IAGZK,SAAWF,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,KAAQH,EAAOG,GAEvB,OAAOG,EAAWP,EAAKC,GAGzB,OAAOD,CACP,CAED,OAAOO,EAAWP,EAAKC,EACxB"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index a9abfed..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 942e1b38dfd65cc4fa8f684675e3007c4b33ea7f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Dec 2024 12:42:24 +0000 Subject: [PATCH 110/119] 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 | 183 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 49 +- SECURITY.md | 5 - benchmark/benchmark.js | 290 -- benchmark/benchmark.ndims.js | 110 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 68 - docs/types/test.ts | 94 - examples/index.js | 45 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 68 - lib/main.js | 112 - package.json | 64 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 514 -- 45 files changed, 4871 insertions(+), 4965 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/benchmark.ndims.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (97%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/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 3f068e8..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-12-01T06:37:14.263Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 740d5ce..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/maybe-broadcast-array) 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 4fadc31..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/maybe-broadcast-array) 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 31edc84..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: '45 9 * * 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 + + ```
@@ -173,7 +164,7 @@ for ( i = 0; i < N; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -236,11 +227,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-maybe-broadcast-array/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor +[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor/tree/esm -[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes +[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm
diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index ba5f734..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,290 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var ndarrayBase = require( '@stdlib/ndarray-base-ctor' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArray = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::base_ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::base_ndarray,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( out.shape[ 0 ] !== shape[ 0 ] ) { - b.fail( 'unexpected result' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.ndims.js b/benchmark/benchmark.ndims.js deleted file mode 100644 index 739b74c..0000000 --- a/benchmark/benchmark.ndims.js +++ /dev/null @@ -1,110 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var array = require( '@stdlib/ndarray-array' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} ndims - number of dimensions to which to broadcast -* @returns {Function} benchmark function -*/ -function createBenchmark( ndims ) { - var shape; - var sh; - var x; - var i; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - sh = x.shape; - - shape = []; - for ( i = 0; i < ndims; i++ ) { - shape.push( 0 ); - } - for ( i = ndims; i >= 1; i-- ) { - if ( i > sh.length ) { - shape[ ndims-i ] = 5; - } else { - shape[ ndims-i ] = sh[ i-1 ]; - } - } - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( x, shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var min; - var max; - var f; - var i; - - min = 2; - max = 10; - - for ( i = min; i <= max; i++ ) { - f = createBenchmark( i ); - bench( pkg+'::ndarray,2d:from_ndims=2,to_ndims='+i, f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index e45b5c4..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/maybe-broadcast-array" -%% click B href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/maybe-broadcast-array -[production-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 71859ce..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import maybeBroadcastArray from '../docs/types/index'; -export = maybeBroadcastArray; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 4b04e84..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var o=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var s=o(function(l,n){ -var u=require('@stdlib/ndarray-base-broadcast-array/dist'),v=require('@stdlib/ndarray-base-shape/dist');function c(e,r){var i,a,t;if(a=r.length,i=v(e,!1),i.length===a){for(t=0;t\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nmodule.exports = maybeBroadcastArray;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape.\n*\n* @module @stdlib/ndarray-base-maybe-broadcast-array\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var maybeBroadcastArray = require( '@stdlib/ndarray-base-maybe-broadcast-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAY,QAAS,sCAAuC,EAC5DC,EAAW,QAAS,4BAA6B,EA8DrD,SAASC,EAAqBC,EAAKC,EAAQ,CAC1C,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAM,OACVC,EAAKJ,EAAUE,EAAK,EAAM,EAGrBE,EAAG,SAAWC,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,CAAE,IAAMH,EAAOG,CAAE,EAEzB,OAAOP,EAAWG,EAAKC,CAAM,EAG/B,OAAOD,CACR,CAEA,OAAOH,EAAWG,EAAKC,CAAM,CAC9B,CAKAL,EAAO,QAAUG,ICjDjB,IAAIM,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "broadcast", "getShape", "maybeBroadcastArray", "arr", "shape", "sh", "N", "i", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 01ecba8..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,68 +0,0 @@ - -{{alias}}( arr, shape ) - Broadcasts an ndarray to a specified shape if and only if the specified - shape differs from the provided ndarray's shape. - - If a provided ndarray has the same shape as the specified shape, the - function returns the provided ndarray. - - If a provided ndarray has a different (broadcast compatible) shape than the - specified shape, the function returns a new (base) ndarray view of the - provided ndarray's data. The view is typically **not** contiguous. As more - than one element of a returned view may refer to the same memory location, - writing to the view may affect multiple elements. If you need to write to - the returned array, copy the array before performing operations which may - mutate elements. - - A returned array view is a "base" ndarray, and, thus, a returned array view - does not perform bounds checking or afford any of the guarantees of the non- - base ndarray constructor. The primary intent of this function is to - broadcast an ndarray-like object within internal implementations and to do - so with minimal overhead. - - The function throws an error if a provided ndarray is incompatible with a - provided shape. - - Parameters - ---------- - arr: ndarray - Input array. - - shape: ArrayLikeObject - Desired shape. - - Returns - ------- - out: ndarray - Broadcasted array. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > var sh = x.shape - [ 2, 2 ] - > var y = {{alias}}( x, [ 3, 2, 2 ] ) - - > sh = y.shape - [ 3, 2, 2 ] - > var v = y.get( 0, 0, 0 ) - 1 - > v = y.get( 0, 0, 1 ) - 2 - > v = y.get( 0, 1, 0 ) - 3 - > v = y.get( 0, 1, 1 ) - 4 - > v = y.get( 1, 0, 0 ) - 1 - > v = y.get( 1, 1, 0 ) - 3 - > v = y.get( 2, 0, 0 ) - 1 - > v = y.get( 2, 1, 1 ) - 4 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 8dc469f..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,94 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ndarray } from '@stdlib/types/ndarray'; -import maybeBroadcastArray = require( './index' ); - -/** -* Mock function to create an ndarray-like object. -* -* @returns ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns an ndarray... -{ - const x = array(); - - maybeBroadcastArray( x, [ 2, 2, 2 ] ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is not provided a first argument which is an ndarray... -{ - maybeBroadcastArray( '5', [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( 5, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( true, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( false, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( null, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( {}, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( [ '5' ], [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( ( x: number ): number => x, [ 2, 2, 2 ] ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a second argument which is an array-like object containing numbers... -{ - const x = array(); - - maybeBroadcastArray( x, '5' ); // $ExpectError - maybeBroadcastArray( x, 5 ); // $ExpectError - maybeBroadcastArray( x, true ); // $ExpectError - maybeBroadcastArray( x, false ); // $ExpectError - maybeBroadcastArray( x, null ); // $ExpectError - maybeBroadcastArray( x, {} ); // $ExpectError - maybeBroadcastArray( x, [ '5' ] ); // $ExpectError - maybeBroadcastArray( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - - maybeBroadcastArray(); // $ExpectError - maybeBroadcastArray( x ); // $ExpectError - maybeBroadcastArray( x, [ 1, 2, 3 ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index e787d6e..0000000 --- a/examples/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 array = require( '@stdlib/ndarray-array' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var maybeBroadcastArray = require( './../lib' ); - -// Create a 2x2 array: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -// returns - -// Broadcast the array to 3x2x2: -var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -// returns - -// Retrieve the shape: -var sh = y.shape; -// returns [ 3, 2, 2 ] - -// Retrieve the number of elements: -var N = numel( sh ); - -// Loop through the array elements... -var i; -for ( i = 0; i < N; i++ ) { - console.log( 'Y[%s] = %d', ind2sub( sh, i ).join( ', ' ), y.iget( i ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 97% rename from docs/types/index.d.ts rename to index.d.ts index f354818..97640ae 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..7290520 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.2-esm/index.mjs";function e(e,s){var n,a,d;if(a=s.length,(n=t(e,!1)).length===a){for(d=0;d\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArray;\n"],"names":["maybeBroadcastArray","arr","shape","sh","N","i","length","getShape","broadcast"],"mappings":";;oMAqFA,SAASA,EAAqBC,EAAKC,GAClC,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAMI,QACVH,EAAKI,EAAUN,GAAK,IAGZK,SAAWF,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,KAAQH,EAAOG,GAEvB,OAAOG,EAAWP,EAAKC,GAGzB,OAAOD,CACP,CAED,OAAOO,EAAWP,EAAKC,EACxB"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 834e930..0000000 --- a/lib/index.js +++ /dev/null @@ -1,68 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* @module @stdlib/ndarray-base-maybe-broadcast-array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var maybeBroadcastArray = require( '@stdlib/ndarray-base-maybe-broadcast-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -*/ - -// 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 e59ca1d..0000000 --- a/lib/main.js +++ /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. -*/ - -'use strict'; - -// MODULES // - -var broadcast = require( '@stdlib/ndarray-base-broadcast-array' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); - - -// MAIN // - -/** -* Broadcasts an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* ## Notes -* -* - If a provided ndarray has the same shape as the specified shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the specified shape, the function returns a new (base) ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to the view may affect multiple elements. If you need to write to the returned array, copy the array before performing operations which may mutate elements. -* -* @param {ndarray} arr - input array -* @param {NonNegativeIntegerArray} shape - desired shape -* @throws {Error} input array cannot have more dimensions than the desired shape -* @throws {Error} input array dimension sizes must be `1` or equal to the corresponding dimension in the provided shape -* @throws {Error} input array and desired shape must be broadcast compatible -* @returns {ndarray} broadcasted array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var y = maybeBroadcastArray( x, [ 3, 2 ] ); -* // throws -*/ -function maybeBroadcastArray( arr, shape ) { - var sh; - var N; - var i; - - N = shape.length; - sh = getShape( arr, false ); - - // Check whether we need to broadcast the input array... - if ( sh.length === N ) { - for ( i = 0; i < N; i++ ) { - // Check whether dimensions match... - if ( sh[ i ] !== shape[ i ] ) { - // We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape... - return broadcast( arr, shape ); - } - } - return arr; - } - // If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape... - return broadcast( arr, shape ); -} - - -// EXPORTS // - -module.exports = maybeBroadcastArray; diff --git a/package.json b/package.json index 0909b3c..489e5cf 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.3", "description": "Broadcast an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's 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", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-base-broadcast-array": "^0.2.2", - "@stdlib/ndarray-base-shape": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-ctor": "^0.2.2", - "@stdlib/ndarray-ind2sub": "^0.2.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -86,9 +29,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..a9abfed --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 7e8e63f..0000000 --- a/test/test.js +++ /dev/null @@ -1,514 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 array = require( '@stdlib/ndarray-array' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var maybeBroadcastArray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof maybeBroadcastArray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a desired shape which has fewer dimensions than the input array', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 ] - }); - - values = [ - [], - [ 2 ], - [ 2, 2 ], - [ 2, 2, 2 ], - [ 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2, 2, 2 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided a shape with '+values[ i ].length+' dimension' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape having a dimension whose size is less than the corresponding dimension in the input array', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 10, 1 ], - [ 10, 10, 2 ], - [ 10, 10, 9 ], - [ 10, 1, 10 ], - [ 10, 2, 10 ], - [ 10, 9, 10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape and an input array shape which are broadcast-incompatible', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 20, 10 ], - [ 10, 10, 100 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function returns a "base" ndarray instance', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = maybeBroadcastArray( x, [ 2, 2, 2 ] ); - - t.notEqual( y, x, 'returns new instance' ); - t.strictEqual( y instanceof ndarray, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view over the input array data buffer', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = maybeBroadcastArray( x, [ 2, 2, 2 ] ); - - t.strictEqual( y.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; strides)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, -1 ], 3, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; strides)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, 1 ], 2, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; non-contiguous)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ 4, 2 ], 1, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 5 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 7 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (column-major)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'column-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (same shape)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2, 2 ], - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - // Should return the same instance: - t.strictEqual( y, x, 'returns expected value' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 1, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 1, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (same number of dimensions)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1, 2 ], - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (singleton dimension)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (singleton dimension)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 1, 2 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (0-dimensional array)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1 ]; - x = ndarray( 'generic', data, [], [ 0 ], 0, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); From 1098aa2b2c616d519ef9bc846a7ee06e68d466ee Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 9 Dec 2024 02:14:06 +0000 Subject: [PATCH 111/119] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index a41389b..0909b3c 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,8 @@ "dependencies": { "@stdlib/ndarray-base-broadcast-array": "^0.2.2", "@stdlib/ndarray-base-shape": "^0.2.2", - "@stdlib/types": "^0.4.3" + "@stdlib/types": "^0.4.3", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, "devDependencies": { "@stdlib/array-float64": "^0.2.2", @@ -90,4 +91,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From 601ab17446440d1c4ef913ec80e4e2a1333b3c7a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 9 Dec 2024 02:33:40 +0000 Subject: [PATCH 112/119] Remove files --- index.d.ts | 81 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4928 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 97640ae..0000000 --- a/index.d.ts +++ /dev/null @@ -1,81 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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'; -import { ndarray } from '@stdlib/types/ndarray'; - -/** -* Broadcasts an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* ## Notes -* -* - The function throws an error if a provided ndarray is incompatible with a provided shape. -* - If a provided ndarray has the same shape as the specified shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the specified shape, the function returns a new (base) ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to the view may affect multiple elements. If you need to write to the returned array, copy the array before performing operations which may mutate elements. -* - A returned array view is a "base" ndarray, and, thus, a returned array view does not perform bounds checking or afford any of the guarantees of the non-base ndarray constructor. The primary intent of this function is to broadcast an ndarray-like object within internal implementations and to do so with minimal overhead. -* -* @param arr - input array -* @param shape - desired shape -* @throws input array cannot have more dimensions than the desired shape -* @throws input array dimension sizes must be `1` or equal to the corresponding dimension in the provided shape -* @throws input array and desired shape must be broadcast compatible -* @returns broadcasted array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -*/ -declare function maybeBroadcastArray( arr: ndarray, shape: ArrayLike ): ndarray; - - -// EXPORTS // - -export = maybeBroadcastArray; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 7290520..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.2-esm/index.mjs";function e(e,s){var n,a,d;if(a=s.length,(n=t(e,!1)).length===a){for(d=0;d\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArray;\n"],"names":["maybeBroadcastArray","arr","shape","sh","N","i","length","getShape","broadcast"],"mappings":";;oMAqFA,SAASA,EAAqBC,EAAKC,GAClC,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAMI,QACVH,EAAKI,EAAUN,GAAK,IAGZK,SAAWF,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,KAAQH,EAAOG,GAEvB,OAAOG,EAAWP,EAAKC,GAGzB,OAAOD,CACP,CAED,OAAOO,EAAWP,EAAKC,EACxB"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index a9abfed..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From f8074970ba112bebb7433075d936efb5e62e83f9 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 9 Dec 2024 02:33:57 +0000 Subject: [PATCH 113/119] 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 | 183 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 49 +- SECURITY.md | 5 - benchmark/benchmark.js | 290 -- benchmark/benchmark.ndims.js | 110 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 68 - docs/types/test.ts | 94 - examples/index.js | 45 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 68 - lib/main.js | 112 - package.json | 64 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 514 -- 45 files changed, 4871 insertions(+), 4965 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/benchmark.ndims.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (97%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/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 143b0b3..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-12-09T02:06:54.323Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 740d5ce..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/maybe-broadcast-array) 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 4fadc31..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/maybe-broadcast-array) 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 31edc84..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: '45 9 * * 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 + + ```
@@ -173,7 +164,7 @@ for ( i = 0; i < N; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -236,11 +227,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-maybe-broadcast-array/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor +[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor/tree/esm -[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes +[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm
diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index ba5f734..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,290 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var ndarrayBase = require( '@stdlib/ndarray-base-ctor' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArray = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::base_ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::base_ndarray,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( out.shape[ 0 ] !== shape[ 0 ] ) { - b.fail( 'unexpected result' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.ndims.js b/benchmark/benchmark.ndims.js deleted file mode 100644 index 739b74c..0000000 --- a/benchmark/benchmark.ndims.js +++ /dev/null @@ -1,110 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var array = require( '@stdlib/ndarray-array' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} ndims - number of dimensions to which to broadcast -* @returns {Function} benchmark function -*/ -function createBenchmark( ndims ) { - var shape; - var sh; - var x; - var i; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - sh = x.shape; - - shape = []; - for ( i = 0; i < ndims; i++ ) { - shape.push( 0 ); - } - for ( i = ndims; i >= 1; i-- ) { - if ( i > sh.length ) { - shape[ ndims-i ] = 5; - } else { - shape[ ndims-i ] = sh[ i-1 ]; - } - } - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( x, shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var min; - var max; - var f; - var i; - - min = 2; - max = 10; - - for ( i = min; i <= max; i++ ) { - f = createBenchmark( i ); - bench( pkg+'::ndarray,2d:from_ndims=2,to_ndims='+i, f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index e45b5c4..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/maybe-broadcast-array" -%% click B href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/maybe-broadcast-array -[production-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 71859ce..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import maybeBroadcastArray from '../docs/types/index'; -export = maybeBroadcastArray; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 4b04e84..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var o=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var s=o(function(l,n){ -var u=require('@stdlib/ndarray-base-broadcast-array/dist'),v=require('@stdlib/ndarray-base-shape/dist');function c(e,r){var i,a,t;if(a=r.length,i=v(e,!1),i.length===a){for(t=0;t\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nmodule.exports = maybeBroadcastArray;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape.\n*\n* @module @stdlib/ndarray-base-maybe-broadcast-array\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var maybeBroadcastArray = require( '@stdlib/ndarray-base-maybe-broadcast-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAY,QAAS,sCAAuC,EAC5DC,EAAW,QAAS,4BAA6B,EA8DrD,SAASC,EAAqBC,EAAKC,EAAQ,CAC1C,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAM,OACVC,EAAKJ,EAAUE,EAAK,EAAM,EAGrBE,EAAG,SAAWC,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,CAAE,IAAMH,EAAOG,CAAE,EAEzB,OAAOP,EAAWG,EAAKC,CAAM,EAG/B,OAAOD,CACR,CAEA,OAAOH,EAAWG,EAAKC,CAAM,CAC9B,CAKAL,EAAO,QAAUG,ICjDjB,IAAIM,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "broadcast", "getShape", "maybeBroadcastArray", "arr", "shape", "sh", "N", "i", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 01ecba8..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,68 +0,0 @@ - -{{alias}}( arr, shape ) - Broadcasts an ndarray to a specified shape if and only if the specified - shape differs from the provided ndarray's shape. - - If a provided ndarray has the same shape as the specified shape, the - function returns the provided ndarray. - - If a provided ndarray has a different (broadcast compatible) shape than the - specified shape, the function returns a new (base) ndarray view of the - provided ndarray's data. The view is typically **not** contiguous. As more - than one element of a returned view may refer to the same memory location, - writing to the view may affect multiple elements. If you need to write to - the returned array, copy the array before performing operations which may - mutate elements. - - A returned array view is a "base" ndarray, and, thus, a returned array view - does not perform bounds checking or afford any of the guarantees of the non- - base ndarray constructor. The primary intent of this function is to - broadcast an ndarray-like object within internal implementations and to do - so with minimal overhead. - - The function throws an error if a provided ndarray is incompatible with a - provided shape. - - Parameters - ---------- - arr: ndarray - Input array. - - shape: ArrayLikeObject - Desired shape. - - Returns - ------- - out: ndarray - Broadcasted array. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > var sh = x.shape - [ 2, 2 ] - > var y = {{alias}}( x, [ 3, 2, 2 ] ) - - > sh = y.shape - [ 3, 2, 2 ] - > var v = y.get( 0, 0, 0 ) - 1 - > v = y.get( 0, 0, 1 ) - 2 - > v = y.get( 0, 1, 0 ) - 3 - > v = y.get( 0, 1, 1 ) - 4 - > v = y.get( 1, 0, 0 ) - 1 - > v = y.get( 1, 1, 0 ) - 3 - > v = y.get( 2, 0, 0 ) - 1 - > v = y.get( 2, 1, 1 ) - 4 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 8dc469f..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,94 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ndarray } from '@stdlib/types/ndarray'; -import maybeBroadcastArray = require( './index' ); - -/** -* Mock function to create an ndarray-like object. -* -* @returns ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns an ndarray... -{ - const x = array(); - - maybeBroadcastArray( x, [ 2, 2, 2 ] ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is not provided a first argument which is an ndarray... -{ - maybeBroadcastArray( '5', [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( 5, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( true, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( false, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( null, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( {}, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( [ '5' ], [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( ( x: number ): number => x, [ 2, 2, 2 ] ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a second argument which is an array-like object containing numbers... -{ - const x = array(); - - maybeBroadcastArray( x, '5' ); // $ExpectError - maybeBroadcastArray( x, 5 ); // $ExpectError - maybeBroadcastArray( x, true ); // $ExpectError - maybeBroadcastArray( x, false ); // $ExpectError - maybeBroadcastArray( x, null ); // $ExpectError - maybeBroadcastArray( x, {} ); // $ExpectError - maybeBroadcastArray( x, [ '5' ] ); // $ExpectError - maybeBroadcastArray( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - - maybeBroadcastArray(); // $ExpectError - maybeBroadcastArray( x ); // $ExpectError - maybeBroadcastArray( x, [ 1, 2, 3 ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index e787d6e..0000000 --- a/examples/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 array = require( '@stdlib/ndarray-array' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var maybeBroadcastArray = require( './../lib' ); - -// Create a 2x2 array: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -// returns - -// Broadcast the array to 3x2x2: -var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -// returns - -// Retrieve the shape: -var sh = y.shape; -// returns [ 3, 2, 2 ] - -// Retrieve the number of elements: -var N = numel( sh ); - -// Loop through the array elements... -var i; -for ( i = 0; i < N; i++ ) { - console.log( 'Y[%s] = %d', ind2sub( sh, i ).join( ', ' ), y.iget( i ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 97% rename from docs/types/index.d.ts rename to index.d.ts index f354818..97640ae 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..7290520 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.2-esm/index.mjs";function e(e,s){var n,a,d;if(a=s.length,(n=t(e,!1)).length===a){for(d=0;d\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArray;\n"],"names":["maybeBroadcastArray","arr","shape","sh","N","i","length","getShape","broadcast"],"mappings":";;oMAqFA,SAASA,EAAqBC,EAAKC,GAClC,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAMI,QACVH,EAAKI,EAAUN,GAAK,IAGZK,SAAWF,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,KAAQH,EAAOG,GAEvB,OAAOG,EAAWP,EAAKC,GAGzB,OAAOD,CACP,CAED,OAAOO,EAAWP,EAAKC,EACxB"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 834e930..0000000 --- a/lib/index.js +++ /dev/null @@ -1,68 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* @module @stdlib/ndarray-base-maybe-broadcast-array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var maybeBroadcastArray = require( '@stdlib/ndarray-base-maybe-broadcast-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -*/ - -// 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 e59ca1d..0000000 --- a/lib/main.js +++ /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. -*/ - -'use strict'; - -// MODULES // - -var broadcast = require( '@stdlib/ndarray-base-broadcast-array' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); - - -// MAIN // - -/** -* Broadcasts an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* ## Notes -* -* - If a provided ndarray has the same shape as the specified shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the specified shape, the function returns a new (base) ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to the view may affect multiple elements. If you need to write to the returned array, copy the array before performing operations which may mutate elements. -* -* @param {ndarray} arr - input array -* @param {NonNegativeIntegerArray} shape - desired shape -* @throws {Error} input array cannot have more dimensions than the desired shape -* @throws {Error} input array dimension sizes must be `1` or equal to the corresponding dimension in the provided shape -* @throws {Error} input array and desired shape must be broadcast compatible -* @returns {ndarray} broadcasted array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var y = maybeBroadcastArray( x, [ 3, 2 ] ); -* // throws -*/ -function maybeBroadcastArray( arr, shape ) { - var sh; - var N; - var i; - - N = shape.length; - sh = getShape( arr, false ); - - // Check whether we need to broadcast the input array... - if ( sh.length === N ) { - for ( i = 0; i < N; i++ ) { - // Check whether dimensions match... - if ( sh[ i ] !== shape[ i ] ) { - // We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape... - return broadcast( arr, shape ); - } - } - return arr; - } - // If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape... - return broadcast( arr, shape ); -} - - -// EXPORTS // - -module.exports = maybeBroadcastArray; diff --git a/package.json b/package.json index 0909b3c..489e5cf 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.3", "description": "Broadcast an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's 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", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-base-broadcast-array": "^0.2.2", - "@stdlib/ndarray-base-shape": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-ctor": "^0.2.2", - "@stdlib/ndarray-ind2sub": "^0.2.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -86,9 +29,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..a9abfed --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 7e8e63f..0000000 --- a/test/test.js +++ /dev/null @@ -1,514 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 array = require( '@stdlib/ndarray-array' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var maybeBroadcastArray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof maybeBroadcastArray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a desired shape which has fewer dimensions than the input array', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 ] - }); - - values = [ - [], - [ 2 ], - [ 2, 2 ], - [ 2, 2, 2 ], - [ 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2, 2, 2 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided a shape with '+values[ i ].length+' dimension' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape having a dimension whose size is less than the corresponding dimension in the input array', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 10, 1 ], - [ 10, 10, 2 ], - [ 10, 10, 9 ], - [ 10, 1, 10 ], - [ 10, 2, 10 ], - [ 10, 9, 10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape and an input array shape which are broadcast-incompatible', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 20, 10 ], - [ 10, 10, 100 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function returns a "base" ndarray instance', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = maybeBroadcastArray( x, [ 2, 2, 2 ] ); - - t.notEqual( y, x, 'returns new instance' ); - t.strictEqual( y instanceof ndarray, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view over the input array data buffer', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = maybeBroadcastArray( x, [ 2, 2, 2 ] ); - - t.strictEqual( y.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; strides)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, -1 ], 3, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; strides)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, 1 ], 2, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; non-contiguous)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ 4, 2 ], 1, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 5 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 7 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (column-major)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'column-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (same shape)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2, 2 ], - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - // Should return the same instance: - t.strictEqual( y, x, 'returns expected value' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 1, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 1, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (same number of dimensions)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1, 2 ], - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (singleton dimension)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (singleton dimension)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 1, 2 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (0-dimensional array)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1 ]; - x = ndarray( 'generic', data, [], [ 0 ], 0, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); From 642c32f62824211c7f76526de7f383a4b14e6c0f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 24 Feb 2025 00:53:49 +0000 Subject: [PATCH 114/119] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index a41389b..0909b3c 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,8 @@ "dependencies": { "@stdlib/ndarray-base-broadcast-array": "^0.2.2", "@stdlib/ndarray-base-shape": "^0.2.2", - "@stdlib/types": "^0.4.3" + "@stdlib/types": "^0.4.3", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, "devDependencies": { "@stdlib/array-float64": "^0.2.2", @@ -90,4 +91,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From 0643a90f50a706c6e3a2e94af3d96bbc5b32de4b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 24 Feb 2025 01:06:10 +0000 Subject: [PATCH 115/119] Remove files --- index.d.ts | 81 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4928 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 97640ae..0000000 --- a/index.d.ts +++ /dev/null @@ -1,81 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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'; -import { ndarray } from '@stdlib/types/ndarray'; - -/** -* Broadcasts an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* ## Notes -* -* - The function throws an error if a provided ndarray is incompatible with a provided shape. -* - If a provided ndarray has the same shape as the specified shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the specified shape, the function returns a new (base) ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to the view may affect multiple elements. If you need to write to the returned array, copy the array before performing operations which may mutate elements. -* - A returned array view is a "base" ndarray, and, thus, a returned array view does not perform bounds checking or afford any of the guarantees of the non-base ndarray constructor. The primary intent of this function is to broadcast an ndarray-like object within internal implementations and to do so with minimal overhead. -* -* @param arr - input array -* @param shape - desired shape -* @throws input array cannot have more dimensions than the desired shape -* @throws input array dimension sizes must be `1` or equal to the corresponding dimension in the provided shape -* @throws input array and desired shape must be broadcast compatible -* @returns broadcasted array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -*/ -declare function maybeBroadcastArray( arr: ndarray, shape: ArrayLike ): ndarray; - - -// EXPORTS // - -export = maybeBroadcastArray; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 7290520..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.2-esm/index.mjs";function e(e,s){var n,a,d;if(a=s.length,(n=t(e,!1)).length===a){for(d=0;d\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArray;\n"],"names":["maybeBroadcastArray","arr","shape","sh","N","i","length","getShape","broadcast"],"mappings":";;oMAqFA,SAASA,EAAqBC,EAAKC,GAClC,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAMI,QACVH,EAAKI,EAAUN,GAAK,IAGZK,SAAWF,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,KAAQH,EAAOG,GAEvB,OAAOG,EAAWP,EAAKC,GAGzB,OAAOD,CACP,CAED,OAAOO,EAAWP,EAAKC,EACxB"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index a9abfed..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From fe0f9441b01771fc635b6d8b271c363fe95ff6eb Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 24 Feb 2025 01:06:48 +0000 Subject: [PATCH 116/119] 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 | 183 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 49 +- SECURITY.md | 5 - benchmark/benchmark.js | 290 -- benchmark/benchmark.ndims.js | 110 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 68 - docs/types/test.ts | 94 - examples/index.js | 45 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 68 - lib/main.js | 112 - package.json | 64 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 514 -- 45 files changed, 4871 insertions(+), 4968 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/benchmark.ndims.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (97%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/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 36766c6..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2025-02-24T00:50:38.942Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ce08877..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/maybe-broadcast-array) 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 4fadc31..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/maybe-broadcast-array) 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 31edc84..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: '45 9 * * 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 + + ```
@@ -173,7 +164,7 @@ for ( i = 0; i < N; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -236,11 +227,11 @@ Copyright © 2016-2025. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-maybe-broadcast-array/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor +[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor/tree/esm -[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes +[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm
diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index ba5f734..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,290 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var ndarrayBase = require( '@stdlib/ndarray-base-ctor' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArray = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::base_ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::base_ndarray,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( out.shape[ 0 ] !== shape[ 0 ] ) { - b.fail( 'unexpected result' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.ndims.js b/benchmark/benchmark.ndims.js deleted file mode 100644 index 739b74c..0000000 --- a/benchmark/benchmark.ndims.js +++ /dev/null @@ -1,110 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var array = require( '@stdlib/ndarray-array' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} ndims - number of dimensions to which to broadcast -* @returns {Function} benchmark function -*/ -function createBenchmark( ndims ) { - var shape; - var sh; - var x; - var i; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - sh = x.shape; - - shape = []; - for ( i = 0; i < ndims; i++ ) { - shape.push( 0 ); - } - for ( i = ndims; i >= 1; i-- ) { - if ( i > sh.length ) { - shape[ ndims-i ] = 5; - } else { - shape[ ndims-i ] = sh[ i-1 ]; - } - } - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( x, shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var min; - var max; - var f; - var i; - - min = 2; - max = 10; - - for ( i = min; i <= max; i++ ) { - f = createBenchmark( i ); - bench( pkg+'::ndarray,2d:from_ndims=2,to_ndims='+i, f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index e45b5c4..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/maybe-broadcast-array" -%% click B href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/maybe-broadcast-array -[production-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 71859ce..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import maybeBroadcastArray from '../docs/types/index'; -export = maybeBroadcastArray; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 4b04e84..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var o=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var s=o(function(l,n){ -var u=require('@stdlib/ndarray-base-broadcast-array/dist'),v=require('@stdlib/ndarray-base-shape/dist');function c(e,r){var i,a,t;if(a=r.length,i=v(e,!1),i.length===a){for(t=0;t\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nmodule.exports = maybeBroadcastArray;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape.\n*\n* @module @stdlib/ndarray-base-maybe-broadcast-array\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var maybeBroadcastArray = require( '@stdlib/ndarray-base-maybe-broadcast-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAY,QAAS,sCAAuC,EAC5DC,EAAW,QAAS,4BAA6B,EA8DrD,SAASC,EAAqBC,EAAKC,EAAQ,CAC1C,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAM,OACVC,EAAKJ,EAAUE,EAAK,EAAM,EAGrBE,EAAG,SAAWC,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,CAAE,IAAMH,EAAOG,CAAE,EAEzB,OAAOP,EAAWG,EAAKC,CAAM,EAG/B,OAAOD,CACR,CAEA,OAAOH,EAAWG,EAAKC,CAAM,CAC9B,CAKAL,EAAO,QAAUG,ICjDjB,IAAIM,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "broadcast", "getShape", "maybeBroadcastArray", "arr", "shape", "sh", "N", "i", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 01ecba8..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,68 +0,0 @@ - -{{alias}}( arr, shape ) - Broadcasts an ndarray to a specified shape if and only if the specified - shape differs from the provided ndarray's shape. - - If a provided ndarray has the same shape as the specified shape, the - function returns the provided ndarray. - - If a provided ndarray has a different (broadcast compatible) shape than the - specified shape, the function returns a new (base) ndarray view of the - provided ndarray's data. The view is typically **not** contiguous. As more - than one element of a returned view may refer to the same memory location, - writing to the view may affect multiple elements. If you need to write to - the returned array, copy the array before performing operations which may - mutate elements. - - A returned array view is a "base" ndarray, and, thus, a returned array view - does not perform bounds checking or afford any of the guarantees of the non- - base ndarray constructor. The primary intent of this function is to - broadcast an ndarray-like object within internal implementations and to do - so with minimal overhead. - - The function throws an error if a provided ndarray is incompatible with a - provided shape. - - Parameters - ---------- - arr: ndarray - Input array. - - shape: ArrayLikeObject - Desired shape. - - Returns - ------- - out: ndarray - Broadcasted array. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > var sh = x.shape - [ 2, 2 ] - > var y = {{alias}}( x, [ 3, 2, 2 ] ) - - > sh = y.shape - [ 3, 2, 2 ] - > var v = y.get( 0, 0, 0 ) - 1 - > v = y.get( 0, 0, 1 ) - 2 - > v = y.get( 0, 1, 0 ) - 3 - > v = y.get( 0, 1, 1 ) - 4 - > v = y.get( 1, 0, 0 ) - 1 - > v = y.get( 1, 1, 0 ) - 3 - > v = y.get( 2, 0, 0 ) - 1 - > v = y.get( 2, 1, 1 ) - 4 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 8dc469f..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,94 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ndarray } from '@stdlib/types/ndarray'; -import maybeBroadcastArray = require( './index' ); - -/** -* Mock function to create an ndarray-like object. -* -* @returns ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns an ndarray... -{ - const x = array(); - - maybeBroadcastArray( x, [ 2, 2, 2 ] ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is not provided a first argument which is an ndarray... -{ - maybeBroadcastArray( '5', [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( 5, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( true, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( false, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( null, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( {}, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( [ '5' ], [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( ( x: number ): number => x, [ 2, 2, 2 ] ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a second argument which is an array-like object containing numbers... -{ - const x = array(); - - maybeBroadcastArray( x, '5' ); // $ExpectError - maybeBroadcastArray( x, 5 ); // $ExpectError - maybeBroadcastArray( x, true ); // $ExpectError - maybeBroadcastArray( x, false ); // $ExpectError - maybeBroadcastArray( x, null ); // $ExpectError - maybeBroadcastArray( x, {} ); // $ExpectError - maybeBroadcastArray( x, [ '5' ] ); // $ExpectError - maybeBroadcastArray( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - - maybeBroadcastArray(); // $ExpectError - maybeBroadcastArray( x ); // $ExpectError - maybeBroadcastArray( x, [ 1, 2, 3 ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index e787d6e..0000000 --- a/examples/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 array = require( '@stdlib/ndarray-array' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var maybeBroadcastArray = require( './../lib' ); - -// Create a 2x2 array: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -// returns - -// Broadcast the array to 3x2x2: -var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -// returns - -// Retrieve the shape: -var sh = y.shape; -// returns [ 3, 2, 2 ] - -// Retrieve the number of elements: -var N = numel( sh ); - -// Loop through the array elements... -var i; -for ( i = 0; i < N; i++ ) { - console.log( 'Y[%s] = %d', ind2sub( sh, i ).join( ', ' ), y.iget( i ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 97% rename from docs/types/index.d.ts rename to index.d.ts index f354818..97640ae 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..ed74112 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.2-esm/index.mjs";function e(e,s){var n,a,d;if(a=s.length,(n=t(e,!1)).length===a){for(d=0;d\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArray;\n"],"names":["maybeBroadcastArray","arr","shape","sh","N","i","length","getShape","broadcast"],"mappings":";;oMAqFA,SAASA,EAAqBC,EAAKC,GAClC,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAMI,QACVH,EAAKI,EAAUN,GAAK,IAGZK,SAAWF,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,KAAQH,EAAOG,GAEvB,OAAOG,EAAWP,EAAKC,GAGzB,OAAOD,CACP,CAED,OAAOO,EAAWP,EAAKC,EACxB"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 834e930..0000000 --- a/lib/index.js +++ /dev/null @@ -1,68 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* @module @stdlib/ndarray-base-maybe-broadcast-array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var maybeBroadcastArray = require( '@stdlib/ndarray-base-maybe-broadcast-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -*/ - -// 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 e59ca1d..0000000 --- a/lib/main.js +++ /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. -*/ - -'use strict'; - -// MODULES // - -var broadcast = require( '@stdlib/ndarray-base-broadcast-array' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); - - -// MAIN // - -/** -* Broadcasts an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* ## Notes -* -* - If a provided ndarray has the same shape as the specified shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the specified shape, the function returns a new (base) ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to the view may affect multiple elements. If you need to write to the returned array, copy the array before performing operations which may mutate elements. -* -* @param {ndarray} arr - input array -* @param {NonNegativeIntegerArray} shape - desired shape -* @throws {Error} input array cannot have more dimensions than the desired shape -* @throws {Error} input array dimension sizes must be `1` or equal to the corresponding dimension in the provided shape -* @throws {Error} input array and desired shape must be broadcast compatible -* @returns {ndarray} broadcasted array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var y = maybeBroadcastArray( x, [ 3, 2 ] ); -* // throws -*/ -function maybeBroadcastArray( arr, shape ) { - var sh; - var N; - var i; - - N = shape.length; - sh = getShape( arr, false ); - - // Check whether we need to broadcast the input array... - if ( sh.length === N ) { - for ( i = 0; i < N; i++ ) { - // Check whether dimensions match... - if ( sh[ i ] !== shape[ i ] ) { - // We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape... - return broadcast( arr, shape ); - } - } - return arr; - } - // If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape... - return broadcast( arr, shape ); -} - - -// EXPORTS // - -module.exports = maybeBroadcastArray; diff --git a/package.json b/package.json index 0909b3c..489e5cf 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.3", "description": "Broadcast an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's 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", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-base-broadcast-array": "^0.2.2", - "@stdlib/ndarray-base-shape": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-ctor": "^0.2.2", - "@stdlib/ndarray-ind2sub": "^0.2.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -86,9 +29,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..a9abfed --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 7e8e63f..0000000 --- a/test/test.js +++ /dev/null @@ -1,514 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 array = require( '@stdlib/ndarray-array' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var maybeBroadcastArray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof maybeBroadcastArray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a desired shape which has fewer dimensions than the input array', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 ] - }); - - values = [ - [], - [ 2 ], - [ 2, 2 ], - [ 2, 2, 2 ], - [ 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2, 2, 2 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided a shape with '+values[ i ].length+' dimension' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape having a dimension whose size is less than the corresponding dimension in the input array', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 10, 1 ], - [ 10, 10, 2 ], - [ 10, 10, 9 ], - [ 10, 1, 10 ], - [ 10, 2, 10 ], - [ 10, 9, 10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape and an input array shape which are broadcast-incompatible', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 20, 10 ], - [ 10, 10, 100 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function returns a "base" ndarray instance', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = maybeBroadcastArray( x, [ 2, 2, 2 ] ); - - t.notEqual( y, x, 'returns new instance' ); - t.strictEqual( y instanceof ndarray, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view over the input array data buffer', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = maybeBroadcastArray( x, [ 2, 2, 2 ] ); - - t.strictEqual( y.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; strides)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, -1 ], 3, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; strides)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, 1 ], 2, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; non-contiguous)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ 4, 2 ], 1, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 5 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 7 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (column-major)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'column-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (same shape)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2, 2 ], - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - // Should return the same instance: - t.strictEqual( y, x, 'returns expected value' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 1, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 1, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (same number of dimensions)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1, 2 ], - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (singleton dimension)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (singleton dimension)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 1, 2 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (0-dimensional array)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1 ]; - x = ndarray( 'generic', data, [], [ 0 ], 0, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); From df18b7092a0a8cfbc68cc7a3e7b173d295fba020 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 10 Mar 2025 01:25:07 +0000 Subject: [PATCH 117/119] Transform error messages --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index a41389b..0909b3c 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,8 @@ "dependencies": { "@stdlib/ndarray-base-broadcast-array": "^0.2.2", "@stdlib/ndarray-base-shape": "^0.2.2", - "@stdlib/types": "^0.4.3" + "@stdlib/types": "^0.4.3", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, "devDependencies": { "@stdlib/array-float64": "^0.2.2", @@ -90,4 +91,4 @@ "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} +} \ No newline at end of file From 623df8e21c0df61f8d94ab1fe321963b79c17bc9 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 10 Mar 2025 01:52:56 +0000 Subject: [PATCH 118/119] Remove files --- index.d.ts | 81 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4928 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 97640ae..0000000 --- a/index.d.ts +++ /dev/null @@ -1,81 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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'; -import { ndarray } from '@stdlib/types/ndarray'; - -/** -* Broadcasts an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* ## Notes -* -* - The function throws an error if a provided ndarray is incompatible with a provided shape. -* - If a provided ndarray has the same shape as the specified shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the specified shape, the function returns a new (base) ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to the view may affect multiple elements. If you need to write to the returned array, copy the array before performing operations which may mutate elements. -* - A returned array view is a "base" ndarray, and, thus, a returned array view does not perform bounds checking or afford any of the guarantees of the non-base ndarray constructor. The primary intent of this function is to broadcast an ndarray-like object within internal implementations and to do so with minimal overhead. -* -* @param arr - input array -* @param shape - desired shape -* @throws input array cannot have more dimensions than the desired shape -* @throws input array dimension sizes must be `1` or equal to the corresponding dimension in the provided shape -* @throws input array and desired shape must be broadcast compatible -* @returns broadcasted array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -*/ -declare function maybeBroadcastArray( arr: ndarray, shape: ArrayLike ): ndarray; - - -// EXPORTS // - -export = maybeBroadcastArray; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index ed74112..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.2-esm/index.mjs";function e(e,s){var n,a,d;if(a=s.length,(n=t(e,!1)).length===a){for(d=0;d\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArray;\n"],"names":["maybeBroadcastArray","arr","shape","sh","N","i","length","getShape","broadcast"],"mappings":";;oMAqFA,SAASA,EAAqBC,EAAKC,GAClC,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAMI,QACVH,EAAKI,EAAUN,GAAK,IAGZK,SAAWF,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,KAAQH,EAAOG,GAEvB,OAAOG,EAAWP,EAAKC,GAGzB,OAAOD,CACP,CAED,OAAOO,EAAWP,EAAKC,EACxB"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index a9abfed..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 9ba31f6265ebc1c13f06ca33cdbc6a8532e04153 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 10 Mar 2025 01:53:34 +0000 Subject: [PATCH 119/119] 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 | 183 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 49 +- SECURITY.md | 5 - benchmark/benchmark.js | 290 -- benchmark/benchmark.ndims.js | 110 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 68 - docs/types/test.ts | 94 - examples/index.js | 45 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 68 - lib/main.js | 112 - package.json | 64 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 514 -- 45 files changed, 4871 insertions(+), 4968 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/benchmark.ndims.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (97%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/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 c6ed194..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2025-03-10T01:16:04.949Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ce08877..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/maybe-broadcast-array) 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 4fadc31..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/maybe-broadcast-array) 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 31edc84..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: '45 9 * * 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 + + ```
@@ -173,7 +164,7 @@ for ( i = 0; i < N; i++ ) { ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -236,11 +227,11 @@ Copyright © 2016-2025. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-maybe-broadcast-array/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor +[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray-base-ctor/tree/esm -[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes +[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes/tree/esm
diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index ba5f734..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,290 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 Float64Array = require( '@stdlib/array-float64' ); -var ndarrayBase = require( '@stdlib/ndarray-base-ctor' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArray = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::base_ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::base_ndarray,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ), - ndarrayBase( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = [ - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ), - ndarray( dtype, buffer, shape, strides, offset, order ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], [ 2, 2, 2 ] ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::ndarray_like,2d,same_shape', function benchmark( b ) { - var strides; - var values; - var buffer; - var offset; - var dtype; - var shape; - var order; - var out; - var obj; - var i; - - dtype = 'float64'; - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - order = 'row-major'; - - values = []; - for ( i = 0; i < 5; i++ ) { - obj = { - 'dtype': dtype, - 'data': buffer, - 'shape': shape, - 'strides': strides, - 'offset': offset, - 'order': order - }; - values.push( obj ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( values[ i%values.length ], shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( out.shape[ 0 ] !== shape[ 0 ] ) { - b.fail( 'unexpected result' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.ndims.js b/benchmark/benchmark.ndims.js deleted file mode 100644 index 739b74c..0000000 --- a/benchmark/benchmark.ndims.js +++ /dev/null @@ -1,110 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var array = require( '@stdlib/ndarray-array' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var maybeBroadcastArray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} ndims - number of dimensions to which to broadcast -* @returns {Function} benchmark function -*/ -function createBenchmark( ndims ) { - var shape; - var sh; - var x; - var i; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - sh = x.shape; - - shape = []; - for ( i = 0; i < ndims; i++ ) { - shape.push( 0 ); - } - for ( i = ndims; i >= 1; i-- ) { - if ( i > sh.length ) { - shape[ ndims-i ] = 5; - } else { - shape[ ndims-i ] = sh[ i-1 ]; - } - } - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = maybeBroadcastArray( x, shape ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var min; - var max; - var f; - var i; - - min = 2; - max = 10; - - for ( i = min; i <= max; i++ ) { - f = createBenchmark( i ); - bench( pkg+'::ndarray,2d:from_ndims=2,to_ndims='+i, f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index e45b5c4..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/maybe-broadcast-array" -%% click B href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/maybe-broadcast-array -[production-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 71859ce..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import maybeBroadcastArray from '../docs/types/index'; -export = maybeBroadcastArray; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 4b04e84..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var o=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var s=o(function(l,n){ -var u=require('@stdlib/ndarray-base-broadcast-array/dist'),v=require('@stdlib/ndarray-base-shape/dist');function c(e,r){var i,a,t;if(a=r.length,i=v(e,!1),i.length===a){for(t=0;t\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nmodule.exports = maybeBroadcastArray;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape.\n*\n* @module @stdlib/ndarray-base-maybe-broadcast-array\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var maybeBroadcastArray = require( '@stdlib/ndarray-base-maybe-broadcast-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAY,QAAS,sCAAuC,EAC5DC,EAAW,QAAS,4BAA6B,EA8DrD,SAASC,EAAqBC,EAAKC,EAAQ,CAC1C,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAM,OACVC,EAAKJ,EAAUE,EAAK,EAAM,EAGrBE,EAAG,SAAWC,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,CAAE,IAAMH,EAAOG,CAAE,EAEzB,OAAOP,EAAWG,EAAKC,CAAM,EAG/B,OAAOD,CACR,CAEA,OAAOH,EAAWG,EAAKC,CAAM,CAC9B,CAKAL,EAAO,QAAUG,ICjDjB,IAAIM,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "broadcast", "getShape", "maybeBroadcastArray", "arr", "shape", "sh", "N", "i", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 01ecba8..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,68 +0,0 @@ - -{{alias}}( arr, shape ) - Broadcasts an ndarray to a specified shape if and only if the specified - shape differs from the provided ndarray's shape. - - If a provided ndarray has the same shape as the specified shape, the - function returns the provided ndarray. - - If a provided ndarray has a different (broadcast compatible) shape than the - specified shape, the function returns a new (base) ndarray view of the - provided ndarray's data. The view is typically **not** contiguous. As more - than one element of a returned view may refer to the same memory location, - writing to the view may affect multiple elements. If you need to write to - the returned array, copy the array before performing operations which may - mutate elements. - - A returned array view is a "base" ndarray, and, thus, a returned array view - does not perform bounds checking or afford any of the guarantees of the non- - base ndarray constructor. The primary intent of this function is to - broadcast an ndarray-like object within internal implementations and to do - so with minimal overhead. - - The function throws an error if a provided ndarray is incompatible with a - provided shape. - - Parameters - ---------- - arr: ndarray - Input array. - - shape: ArrayLikeObject - Desired shape. - - Returns - ------- - out: ndarray - Broadcasted array. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > var sh = x.shape - [ 2, 2 ] - > var y = {{alias}}( x, [ 3, 2, 2 ] ) - - > sh = y.shape - [ 3, 2, 2 ] - > var v = y.get( 0, 0, 0 ) - 1 - > v = y.get( 0, 0, 1 ) - 2 - > v = y.get( 0, 1, 0 ) - 3 - > v = y.get( 0, 1, 1 ) - 4 - > v = y.get( 1, 0, 0 ) - 1 - > v = y.get( 1, 1, 0 ) - 3 - > v = y.get( 2, 0, 0 ) - 1 - > v = y.get( 2, 1, 1 ) - 4 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 8dc469f..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,94 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 { ndarray } from '@stdlib/types/ndarray'; -import maybeBroadcastArray = require( './index' ); - -/** -* Mock function to create an ndarray-like object. -* -* @returns ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns an ndarray... -{ - const x = array(); - - maybeBroadcastArray( x, [ 2, 2, 2 ] ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is not provided a first argument which is an ndarray... -{ - maybeBroadcastArray( '5', [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( 5, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( true, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( false, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( null, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( {}, [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( [ '5' ], [ 2, 2, 2 ] ); // $ExpectError - maybeBroadcastArray( ( x: number ): number => x, [ 2, 2, 2 ] ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a second argument which is an array-like object containing numbers... -{ - const x = array(); - - maybeBroadcastArray( x, '5' ); // $ExpectError - maybeBroadcastArray( x, 5 ); // $ExpectError - maybeBroadcastArray( x, true ); // $ExpectError - maybeBroadcastArray( x, false ); // $ExpectError - maybeBroadcastArray( x, null ); // $ExpectError - maybeBroadcastArray( x, {} ); // $ExpectError - maybeBroadcastArray( x, [ '5' ] ); // $ExpectError - maybeBroadcastArray( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - - maybeBroadcastArray(); // $ExpectError - maybeBroadcastArray( x ); // $ExpectError - maybeBroadcastArray( x, [ 1, 2, 3 ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index e787d6e..0000000 --- a/examples/index.js +++ /dev/null @@ -1,45 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 array = require( '@stdlib/ndarray-array' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var maybeBroadcastArray = require( './../lib' ); - -// Create a 2x2 array: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -// returns - -// Broadcast the array to 3x2x2: -var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -// returns - -// Retrieve the shape: -var sh = y.shape; -// returns [ 3, 2, 2 ] - -// Retrieve the number of elements: -var N = numel( sh ); - -// Loop through the array elements... -var i; -for ( i = 0; i < N; i++ ) { - console.log( 'Y[%s] = %d', ind2sub( sh, i ).join( ', ' ), y.iget( i ) ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 97% rename from docs/types/index.d.ts rename to index.d.ts index f354818..97640ae 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..ed74112 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.2-esm/index.mjs";function e(e,s){var n,a,d;if(a=s.length,(n=t(e,!1)).length===a){for(d=0;d\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );\n* // returns \n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns \n*\n* var y = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nexport default maybeBroadcastArray;\n"],"names":["maybeBroadcastArray","arr","shape","sh","N","i","length","getShape","broadcast"],"mappings":";;oMAqFA,SAASA,EAAqBC,EAAKC,GAClC,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAMI,QACVH,EAAKI,EAAUN,GAAK,IAGZK,SAAWF,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,KAAQH,EAAOG,GAEvB,OAAOG,EAAWP,EAAKC,GAGzB,OAAOD,CACP,CAED,OAAOO,EAAWP,EAAKC,EACxB"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 834e930..0000000 --- a/lib/index.js +++ /dev/null @@ -1,68 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* @module @stdlib/ndarray-base-maybe-broadcast-array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var maybeBroadcastArray = require( '@stdlib/ndarray-base-maybe-broadcast-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -*/ - -// 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 e59ca1d..0000000 --- a/lib/main.js +++ /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. -*/ - -'use strict'; - -// MODULES // - -var broadcast = require( '@stdlib/ndarray-base-broadcast-array' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); - - -// MAIN // - -/** -* Broadcasts an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape. -* -* ## Notes -* -* - If a provided ndarray has the same shape as the specified shape, the function returns the provided ndarray. -* - If a provided ndarray has a different (broadcast compatible) shape than the specified shape, the function returns a new (base) ndarray view of the provided ndarray's data. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to the view may affect multiple elements. If you need to write to the returned array, copy the array before performing operations which may mutate elements. -* -* @param {ndarray} arr - input array -* @param {NonNegativeIntegerArray} shape - desired shape -* @throws {Error} input array cannot have more dimensions than the desired shape -* @throws {Error} input array dimension sizes must be `1` or equal to the corresponding dimension in the provided shape -* @throws {Error} input array and desired shape must be broadcast compatible -* @returns {ndarray} broadcasted array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = maybeBroadcastArray( x, [ 3, 2, 2 ] ); -* // returns -* -* var shy = y.shape; -* // returns [ 3, 2, 2 ] -* -* var v = y.get( 0, 0, 0 ); -* // returns 1 -* -* v = y.get( 0, 0, 1 ); -* // returns 2 -* -* v = y.get( 1, 0, 0 ); -* // returns 1 -* -* v = y.get( 1, 1, 0 ); -* // returns 3 -* -* v = y.get( 2, 0, 0 ); -* // returns 1 -* -* v = y.get( 2, 1, 1 ); -* // returns 4 -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var y = maybeBroadcastArray( x, [ 3, 2 ] ); -* // throws -*/ -function maybeBroadcastArray( arr, shape ) { - var sh; - var N; - var i; - - N = shape.length; - sh = getShape( arr, false ); - - // Check whether we need to broadcast the input array... - if ( sh.length === N ) { - for ( i = 0; i < N; i++ ) { - // Check whether dimensions match... - if ( sh[ i ] !== shape[ i ] ) { - // We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape... - return broadcast( arr, shape ); - } - } - return arr; - } - // If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape... - return broadcast( arr, shape ); -} - - -// EXPORTS // - -module.exports = maybeBroadcastArray; diff --git a/package.json b/package.json index 0909b3c..489e5cf 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.3", "description": "Broadcast an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's 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", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,40 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-base-broadcast-array": "^0.2.2", - "@stdlib/ndarray-base-shape": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-ctor": "^0.2.2", - "@stdlib/ndarray-ind2sub": "^0.2.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -86,9 +29,8 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" } -} \ No newline at end of file +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..a9abfed --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 7e8e63f..0000000 --- a/test/test.js +++ /dev/null @@ -1,514 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 array = require( '@stdlib/ndarray-array' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var maybeBroadcastArray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof maybeBroadcastArray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a desired shape which has fewer dimensions than the input array', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 ] - }); - - values = [ - [], - [ 2 ], - [ 2, 2 ], - [ 2, 2, 2 ], - [ 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2, 2 ], - [ 2, 2, 2, 2, 2, 2, 2, 2, 2 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided a shape with '+values[ i ].length+' dimension' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape having a dimension whose size is less than the corresponding dimension in the input array', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 10, 1 ], - [ 10, 10, 2 ], - [ 10, 10, 9 ], - [ 10, 1, 10 ], - [ 10, 2, 10 ], - [ 10, 9, 10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape and an input array shape which are broadcast-incompatible', function test( t ) { - var values; - var x; - var i; - - x = array({ - 'shape': [ 10, 10 ] - }); - - values = [ - [ 10, 20, 10 ], - [ 10, 10, 100 ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - maybeBroadcastArray( x, value ); - }; - } -}); - -tape( 'the function returns a "base" ndarray instance', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = maybeBroadcastArray( x, [ 2, 2, 2 ] ); - - t.notEqual( y, x, 'returns new instance' ); - t.strictEqual( y instanceof ndarray, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view over the input array data buffer', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = maybeBroadcastArray( x, [ 2, 2, 2 ] ); - - t.strictEqual( y.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; strides)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, -1 ], 3, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; strides)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ -2, 1 ], 2, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (row-major; non-contiguous)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = ndarray( 'generic', data, [ 2, 2 ], [ 4, 2 ], 1, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 5 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 7 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (column-major)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2 ], - 'order': 'column-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (same shape)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 2, 2 ], - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - // Should return the same instance: - t.strictEqual( y, x, 'returns expected value' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 1, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 1, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (same number of dimensions)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2, 3, 4 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1, 2 ], - 'order': 'row-major' - }); - - expected = [ 2, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (singleton dimension)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 2, 1 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (singleton dimension)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1, 2 ]; - x = array( data, { - 'dtype': 'generic', - 'shape': [ 1, 2 ], - 'order': 'row-major' - }); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -}); - -tape( 'the function broadcasts an input array (0-dimensional array)', function test( t ) { - var expected; - var actual; - var data; - var x; - var y; - var v; - var i; - - data = [ 1 ]; - x = ndarray( 'generic', data, [], [ 0 ], 0, 'row-major' ); - - expected = [ 5, 2, 2 ]; - y = maybeBroadcastArray( x, expected ); - - actual = y.shape; - t.deepEqual( actual, expected, 'returns expected shape' ); - - for ( i = 0; i < expected[ 0 ]; i++ ) { - v = y.get( i, 0, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' ); - - v = y.get( i, 0, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' ); - - v = y.get( i, 1, 0 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' ); - - v = y.get( i, 1, 1 ); - t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' ); - } - t.end(); -});