From 35cc7a0fba6a3bc4180e83ca34ecdc0559241fc7 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Apr 2022 12:33:28 +0000 Subject: [PATCH 01/91] Auto-generated commit 46c0bf65547897c9c297fdb59e1815a6e721f004 --- CONTRIBUTORS | 28 + LICENSE | 481 +++++++++ NOTICE | 1 + README.md | 227 +++++ index.d.ts | 80 ++ index.mjs | 4 + index.mjs.map | 1 + package.json | 36 + stats.html | 2689 +++++++++++++++++++++++++++++++++++++++++++++++++ 9 files changed, 3547 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..6cb637c --- /dev/null +++ b/README.md @@ -0,0 +1,227 @@ + + +# broadcastArray + +[![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. + + + +
+ +
+ + + + + + + +
+ +## Usage + +```javascript +import broadcastArray from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@esm/index.mjs'; +``` + +#### broadcastArray( arr, shape ) + +Broadcasts an [ndarray][@stdlib/ndarray/base/ctor] to a specified `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 = broadcastArray( 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. +- The returned [ndarray][@stdlib/ndarray/base/ctor] is a view on the input [ndarray][@stdlib/ndarray/base/ctor] 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 [ndarray][@stdlib/ndarray/base/ctor], copy the [ndarray][@stdlib/ndarray/base/ctor] **before** performing operations which may mutate elements. +- The returned [ndarray][@stdlib/ndarray/base/ctor] is a "base" [ndarray][@stdlib/ndarray/base/ctor], and, thus, the returned [ndarray][@stdlib/ndarray/base/ctor] 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. +- The function always returns a new [ndarray][@stdlib/ndarray/base/ctor] instance even if the input [ndarray][@stdlib/ndarray/base/ctor] shape and the desired shape are the same. + +
+ + + + + +
+ +## 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..a0d0239 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,80 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2021 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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. +* +* ## Notes +* +* - The function throws an error if a provided ndarray is incompatible with a provided shape. +* - The 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. +* - The returned array is a "base" ndarray, and, thus, the returned array 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 always returns a new ndarray instance even if the input ndarray shape and the desired shape are the same. +* +* @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 +* @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 = broadcastArray( 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 broadcastArray( arr: ndarray, shape: ArrayLike ): ndarray; // tslint:disable-line:max-line-length + + +// EXPORTS // + +export = broadcastArray; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..a7e9f13 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@esm/index.mjs";var s=e,a=r,n=function(e){var r,s;for(r=[],s=0;s=0;m--)if(!((c=p-d+m)<0)){if(f=o[c],0!==(t=r[m])&&t\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction broadcastArray( arr, shape ) {\n\tvar strides;\n\tvar dim;\n\tvar sh;\n\tvar st;\n\tvar N;\n\tvar M;\n\tvar d;\n\tvar i;\n\tvar j;\n\n\tN = shape.length;\n\tsh = arr.shape;\n\tM = sh.length;\n\tif ( N < M ) {\n\t\tthrow new Error( 'invalid argument. Cannot broadcast an array to a shape having fewer dimensions. Arrays can only be broadcasted to shapes having the same or more dimensions.' );\n\t}\n\t// Initialize a strides array...\n\tstrides = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tstrides.push( 0 );\n\t}\n\t// Determine the output array strides...\n\tst = arr.strides;\n\tfor ( i = N-1; i >= 0; i-- ) {\n\t\tj = M - N + i;\n\t\tif ( j < 0 ) {\n\t\t\t// Prepended singleton dimension; stride is zero...\n\t\t\tcontinue;\n\t\t}\n\t\td = sh[ j ];\n\t\tdim = shape[ i ];\n\t\tif ( dim !== 0 && dim < d ) {\n\t\t\tthrow new Error( format( 'invalid argument. Input array cannot be broadcast to the specified shape, as the specified shape has a dimension whose size is less than the size of the corresponding dimension in the input array. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t\tif ( d === dim ) {\n\t\t\tstrides[ i ] = st[ j ];\n\t\t} else if ( d === 1 ) {\n\t\t\t// In order to broadcast dimensions, we set the stride for that dimension to zero...\n\t\t\tstrides[ i ] = 0;\n\t\t} else {\n\t\t\t// At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when \"tiling\" an array; e.g., `dim=4` and `d=2`)...\n\t\t\tthrow new Error( format( 'invalid argument. Input array and the specified shape are broadcast incompatible. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t}\n\treturn ndarray( arr.dtype, arr.data, copy( shape ), strides, arr.offset, arr.order ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nmodule.exports = broadcastArray;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast an ndarray to a specified shape.\n*\n* @module @stdlib/ndarray-base-broadcast-array\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var broadcastArray = require( '@stdlib/ndarray-base-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 = broadcastArray( 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":["ndarray","require$$0","format","require$$1","copy","arr","out","i","length","push","lib","shape","strides","dim","sh","st","N","M","d","j","Error","join","dtype","data","offset","order"],"mappings":";;sKAoDA,IC9BIA,EAAUC,EACVC,EAASC,EACTC,EDcJ,SAAoBC,GACnB,IAAIC,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAIF,EAAIG,OAAQD,IAC5BD,EAAIG,KAAMJ,EAAKE,IAEhB,OAAOD,GC0FR,ICrEAI,EDkBA,SAAyBL,EAAKM,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAX,EACAY,EAKJ,IAHAH,EAAIL,EAAMH,SAEVS,GADAH,EAAKT,EAAIM,OACFH,QAEN,MAAM,IAAIY,MAAO,gKAIlB,IADAR,EAAU,GACJL,EAAI,EAAGA,EAAIS,EAAGT,IACnBK,EAAQH,KAAM,GAIf,IADAM,EAAKV,EAAIO,QACHL,EAAIS,EAAE,EAAGT,GAAK,EAAGA,IAEtB,MADAY,EAAIF,EAAID,EAAIT,GACH,GAAT,CAMA,GAFAW,EAAIJ,EAAIK,GAEK,KADbN,EAAMF,EAAOJ,KACKM,EAAMK,EACvB,MAAM,IAAIE,MAAOlB,EAAQ,8PAA+PE,EAAMU,GAAKO,KAAM,MAAQjB,EAAMO,GAAQU,KAAM,MAAQd,IAE9U,GAAKW,IAAML,EACVD,EAASL,GAAMQ,EAAII,OACb,CAAA,GAAW,IAAND,EAKX,MAAM,IAAIE,MAAOlB,EAAQ,2IAA4IE,EAAMU,GAAKO,KAAM,MAAQjB,EAAMO,GAAQU,KAAM,MAAQd,IAH1NK,EAASL,GAAM,GAMjB,OAAOP,EAASK,EAAIiB,MAAOjB,EAAIkB,KAAMnB,EAAMO,GAASC,EAASP,EAAImB,OAAQnB,EAAIoB"} \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..663e1a1 --- /dev/null +++ b/package.json @@ -0,0 +1,36 @@ +{ + "name": "@stdlib/ndarray-base-broadcast-array", + "version": "0.0.0", + "description": "Broadcast an ndarray to a specified 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-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..cef73d8 --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + From 25a127a6aea286e3eb175dcc10dd38ca0a33cf7c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 30 Jun 2022 23:14:47 +0000 Subject: [PATCH 02/91] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index fca038e..8aa2804 100644 --- a/lib/main.js +++ b/lib/main.js @@ -21,7 +21,7 @@ // MODULES // var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var copy = require( './copy_array.js' ); @@ -98,7 +98,7 @@ function broadcastArray( arr, shape ) { sh = arr.shape; M = sh.length; if ( N < M ) { - throw new Error( 'invalid argument. Cannot broadcast an array to a shape having fewer dimensions. Arrays can only be broadcasted to shapes having the same or more dimensions.' ); + throw new Error( format( '0Lx0Z' ) ); } // Initialize a strides array... strides = []; @@ -116,7 +116,7 @@ function broadcastArray( arr, shape ) { d = sh[ j ]; dim = shape[ i ]; if ( dim !== 0 && dim < d ) { - throw new Error( format( 'invalid argument. Input array cannot be broadcast to the specified shape, as the specified shape has a dimension whose size is less than the size of the corresponding dimension in the input array. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); + throw new Error( format( '0Lx5T', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); } if ( d === dim ) { strides[ i ] = st[ j ]; @@ -125,7 +125,7 @@ function broadcastArray( arr, shape ) { strides[ i ] = 0; } else { // At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when "tiling" an array; e.g., `dim=4` and `d=2`)... - throw new Error( format( 'invalid argument. Input array and the specified shape are broadcast incompatible. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); + throw new Error( format( '0Lx5U', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); } } return ndarray( arr.dtype, arr.data, copy( shape ), strides, arr.offset, arr.order ); // eslint-disable-line max-len diff --git a/package.json b/package.json index 96b6613..2c99fad 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ }, "dependencies": { "@stdlib/ndarray-base-ctor": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x" }, "devDependencies": { From 262565eb3c485b8d937949ac5245ff0ab9b7c647 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Jul 2022 10:39:54 +0000 Subject: [PATCH 03/91] Remove files --- index.d.ts | 80 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2774 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 a0d0239..0000000 --- a/index.d.ts +++ /dev/null @@ -1,80 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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. -* -* ## Notes -* -* - The function throws an error if a provided ndarray is incompatible with a provided shape. -* - The 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. -* - The returned array is a "base" ndarray, and, thus, the returned array 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 always returns a new ndarray instance even if the input ndarray shape and the desired shape are the same. -* -* @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 -* @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 = broadcastArray( 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 broadcastArray( arr: ndarray, shape: ArrayLike ): ndarray; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = broadcastArray; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index a7e9f13..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@esm/index.mjs";var s=e,a=r,n=function(e){var r,s;for(r=[],s=0;s=0;m--)if(!((c=p-d+m)<0)){if(f=o[c],0!==(t=r[m])&&t\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction broadcastArray( arr, shape ) {\n\tvar strides;\n\tvar dim;\n\tvar sh;\n\tvar st;\n\tvar N;\n\tvar M;\n\tvar d;\n\tvar i;\n\tvar j;\n\n\tN = shape.length;\n\tsh = arr.shape;\n\tM = sh.length;\n\tif ( N < M ) {\n\t\tthrow new Error( 'invalid argument. Cannot broadcast an array to a shape having fewer dimensions. Arrays can only be broadcasted to shapes having the same or more dimensions.' );\n\t}\n\t// Initialize a strides array...\n\tstrides = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tstrides.push( 0 );\n\t}\n\t// Determine the output array strides...\n\tst = arr.strides;\n\tfor ( i = N-1; i >= 0; i-- ) {\n\t\tj = M - N + i;\n\t\tif ( j < 0 ) {\n\t\t\t// Prepended singleton dimension; stride is zero...\n\t\t\tcontinue;\n\t\t}\n\t\td = sh[ j ];\n\t\tdim = shape[ i ];\n\t\tif ( dim !== 0 && dim < d ) {\n\t\t\tthrow new Error( format( 'invalid argument. Input array cannot be broadcast to the specified shape, as the specified shape has a dimension whose size is less than the size of the corresponding dimension in the input array. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t\tif ( d === dim ) {\n\t\t\tstrides[ i ] = st[ j ];\n\t\t} else if ( d === 1 ) {\n\t\t\t// In order to broadcast dimensions, we set the stride for that dimension to zero...\n\t\t\tstrides[ i ] = 0;\n\t\t} else {\n\t\t\t// At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when \"tiling\" an array; e.g., `dim=4` and `d=2`)...\n\t\t\tthrow new Error( format( 'invalid argument. Input array and the specified shape are broadcast incompatible. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t}\n\treturn ndarray( arr.dtype, arr.data, copy( shape ), strides, arr.offset, arr.order ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nmodule.exports = broadcastArray;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast an ndarray to a specified shape.\n*\n* @module @stdlib/ndarray-base-broadcast-array\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var broadcastArray = require( '@stdlib/ndarray-base-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 = broadcastArray( 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":["ndarray","require$$0","format","require$$1","copy","arr","out","i","length","push","lib","shape","strides","dim","sh","st","N","M","d","j","Error","join","dtype","data","offset","order"],"mappings":";;sKAoDA,IC9BIA,EAAUC,EACVC,EAASC,EACTC,EDcJ,SAAoBC,GACnB,IAAIC,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAIF,EAAIG,OAAQD,IAC5BD,EAAIG,KAAMJ,EAAKE,IAEhB,OAAOD,GC0FR,ICrEAI,EDkBA,SAAyBL,EAAKM,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAX,EACAY,EAKJ,IAHAH,EAAIL,EAAMH,SAEVS,GADAH,EAAKT,EAAIM,OACFH,QAEN,MAAM,IAAIY,MAAO,gKAIlB,IADAR,EAAU,GACJL,EAAI,EAAGA,EAAIS,EAAGT,IACnBK,EAAQH,KAAM,GAIf,IADAM,EAAKV,EAAIO,QACHL,EAAIS,EAAE,EAAGT,GAAK,EAAGA,IAEtB,MADAY,EAAIF,EAAID,EAAIT,GACH,GAAT,CAMA,GAFAW,EAAIJ,EAAIK,GAEK,KADbN,EAAMF,EAAOJ,KACKM,EAAMK,EACvB,MAAM,IAAIE,MAAOlB,EAAQ,8PAA+PE,EAAMU,GAAKO,KAAM,MAAQjB,EAAMO,GAAQU,KAAM,MAAQd,IAE9U,GAAKW,IAAML,EACVD,EAASL,GAAMQ,EAAII,OACb,CAAA,GAAW,IAAND,EAKX,MAAM,IAAIE,MAAOlB,EAAQ,2IAA4IE,EAAMU,GAAKO,KAAM,MAAQjB,EAAMO,GAAQU,KAAM,MAAQd,IAH1NK,EAASL,GAAM,GAMjB,OAAOP,EAASK,EAAIiB,MAAOjB,EAAIkB,KAAMnB,EAAMO,GAASC,EAASP,EAAImB,OAAQnB,EAAIoB"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index cef73d8..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 6421aa207f7fede99f3e11040e9c71055c46d24d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Jul 2022 10:40:39 +0000 Subject: [PATCH 04/91] Auto-generated commit --- .editorconfig | 181 -- .eslintrc.js | 1 - .gitattributes | 33 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 681 ------ .github/workflows/publish.yml | 157 -- .github/workflows/test.yml | 92 - .github/workflows/test_bundles.yml | 180 -- .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 178 -- .npmignore | 227 -- .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 ---- README.md | 47 +- benchmark/benchmark.js | 161 -- benchmark/benchmark.ndims.js | 110 - branches.md | 53 - docs/repl.txt | 65 - docs/types/test.ts | 94 - examples/index.js | 49 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/copy_array.js | 53 - lib/index.js | 68 - lib/main.js | 137 -- package.json | 60 +- stats.html | 2689 +++++++++++++++++++++ test/test.js | 511 ---- 39 files changed, 2717 insertions(+), 4236 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 (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/copy_array.js 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 b2755c5..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-06-30T22:38:10.574Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 6c59584..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-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 9a95c7d..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-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 + + ```
@@ -164,7 +157,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]. @@ -224,11 +217,11 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-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 7983cf3..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,161 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 broadcastArray = 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 = broadcastArray( 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', 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 = broadcastArray( 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', 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 = broadcastArray( 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(); -}); diff --git a/benchmark/benchmark.ndims.js b/benchmark/benchmark.ndims.js deleted file mode 100644 index 141a816..0000000 --- a/benchmark/benchmark.ndims.js +++ /dev/null @@ -1,110 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 broadcastArray = 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 = broadcastArray( 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 1aef646..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-array" -click B href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/main" -click C href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/production" -click D href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-array -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-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 db0f44c..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,65 +0,0 @@ - -{{alias}}( arr, shape ) - Broadcasts an ndarray to a specified shape. - - The 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. - - The returned array is a "base" ndarray, and, thus, the returned array 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. - - The function always returns a new ndarray instance even if the input ndarray - shape and the desired shape are the same. - - 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 4041dc7..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,94 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 broadcastArray = 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(); - - broadcastArray( x, [ 2, 2, 2 ] ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is not provided a first argument which is an ndarray... -{ - broadcastArray( '5', [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( 5, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( true, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( false, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( null, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( {}, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( [ '5' ], [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( ( 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(); - - broadcastArray( x, '5' ); // $ExpectError - broadcastArray( x, 5 ); // $ExpectError - broadcastArray( x, true ); // $ExpectError - broadcastArray( x, false ); // $ExpectError - broadcastArray( x, null ); // $ExpectError - broadcastArray( x, {} ); // $ExpectError - broadcastArray( x, [ '5' ] ); // $ExpectError - broadcastArray( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - - broadcastArray(); // $ExpectError - broadcastArray( x ); // $ExpectError - broadcastArray( x, [ 1, 2, 3 ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index f0dc7b6..0000000 --- a/examples/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 broadcastArray = require( './../lib' ); - -// Create a 2x2 array: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -// returns - -// Broadcast the array to 3x2x2: -var y = broadcastArray( 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 sub; -var v; -var i; -for ( i = 0; i < N; i++ ) { - v = y.iget( i ); - sub = ind2sub( sh, i ); - console.log( 'Y[%s] = %d', sub.join( ', ' ), v ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index f8117ef..a0d0239 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..bf09bce --- /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-ctor@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";function e(r){var t,e;for(t=[],e=0;e=0;l--)if(!((m=a-h+l)<0)){if(j=f[m],0!==(i=n[l])&&i\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction broadcastArray( arr, shape ) {\n\tvar strides;\n\tvar dim;\n\tvar sh;\n\tvar st;\n\tvar N;\n\tvar M;\n\tvar d;\n\tvar i;\n\tvar j;\n\n\tN = shape.length;\n\tsh = arr.shape;\n\tM = sh.length;\n\tif ( N < M ) {\n\t\tthrow new Error( format( '0Lx0Z' ) );\n\t}\n\t// Initialize a strides array...\n\tstrides = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tstrides.push( 0 );\n\t}\n\t// Determine the output array strides...\n\tst = arr.strides;\n\tfor ( i = N-1; i >= 0; i-- ) {\n\t\tj = M - N + i;\n\t\tif ( j < 0 ) {\n\t\t\t// Prepended singleton dimension; stride is zero...\n\t\t\tcontinue;\n\t\t}\n\t\td = sh[ j ];\n\t\tdim = shape[ i ];\n\t\tif ( dim !== 0 && dim < d ) {\n\t\t\tthrow new Error( format( '0Lx5T', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t\tif ( d === dim ) {\n\t\t\tstrides[ i ] = st[ j ];\n\t\t} else if ( d === 1 ) {\n\t\t\t// In order to broadcast dimensions, we set the stride for that dimension to zero...\n\t\t\tstrides[ i ] = 0;\n\t\t} else {\n\t\t\t// At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when \"tiling\" an array; e.g., `dim=4` and `d=2`)...\n\t\t\tthrow new Error( format( '0Lx5U', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t}\n\treturn ndarray( arr.dtype, arr.data, copy( shape ), strides, arr.offset, arr.order ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nexport default broadcastArray;\n"],"names":["copyArray","arr","out","i","length","push","broadcastArray","shape","strides","dim","sh","st","N","M","d","j","Error","format","copy","join","ndarray","dtype","data","offset","order"],"mappings":";;+KAsCA,SAASA,EAAWC,GACnB,IAAIC,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAIF,EAAIG,OAAQD,IAC5BD,EAAIG,KAAMJ,EAAKE,IAEhB,OAAOD,ECuCR,SAASI,EAAgBL,EAAKM,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAX,EACAY,EAKJ,IAHAH,EAAIL,EAAMH,SAEVS,GADAH,EAAKT,EAAIM,OACFH,QAEN,MAAM,IAAIY,MAAOC,EAAQ,UAI1B,IADAT,EAAU,GACJL,EAAI,EAAGA,EAAIS,EAAGT,IACnBK,EAAQH,KAAM,GAIf,IADAM,EAAKV,EAAIO,QACHL,EAAIS,EAAE,EAAGT,GAAK,EAAGA,IAEtB,MADAY,EAAIF,EAAID,EAAIT,GACH,GAAT,CAMA,GAFAW,EAAIJ,EAAIK,GAEK,KADbN,EAAMF,EAAOJ,KACKM,EAAMK,EACvB,MAAM,IAAIE,MAAOC,EAAQ,QAASC,EAAMR,GAAKS,KAAM,MAAQD,EAAMX,GAAQY,KAAM,MAAQhB,IAExF,GAAKW,IAAML,EACVD,EAASL,GAAMQ,EAAII,OACb,IAAW,IAAND,EAKX,MAAM,IAAIE,MAAOC,EAAQ,QAASC,EAAMR,GAAKS,KAAM,MAAQD,EAAMX,GAAQY,KAAM,MAAQhB,IAHvFK,EAASL,GAAM,GAMjB,OAAOiB,EAASnB,EAAIoB,MAAOpB,EAAIqB,KAAMJ,EAAMX,GAASC,EAASP,EAAIsB,OAAQtB,EAAIuB"} \ No newline at end of file diff --git a/lib/copy_array.js b/lib/copy_array.js deleted file mode 100644 index 6c9a427..0000000 --- a/lib/copy_array.js +++ /dev/null @@ -1,53 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN / - -/** -* Copies an array-like object to an array. -* -* @private -* @param {ArrayLikeObject} arr - input array -* @returns {Array} output array -* -* @example -* var arr = [ 1, 2, 3 ]; -* -* var out = copyArray( arr ); -* // returns [ 1, 2, 3 ] -* -* var bool = ( out === arr ); -* // returns false -*/ -function copyArray( arr ) { - var out; - var i; - - out = []; - for ( i = 0; i < arr.length; i++ ) { - out.push( arr[ i ] ); - } - return out; -} - - -// EXPORTS // - -module.exports = copyArray; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index b6aaa86..0000000 --- a/lib/index.js +++ /dev/null @@ -1,68 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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. -* -* @module @stdlib/ndarray-base-broadcast-array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var broadcastArray = require( '@stdlib/ndarray-base-broadcast-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = broadcastArray( 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 8aa2804..0000000 --- a/lib/main.js +++ /dev/null @@ -1,137 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var copy = require( './copy_array.js' ); - - -// MAIN // - -/** -* Broadcasts an ndarray to a specified shape. -* -* ## Notes -* -* - The 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. -* -* @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 = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] ); -* // throws -*/ -function broadcastArray( arr, shape ) { - var strides; - var dim; - var sh; - var st; - var N; - var M; - var d; - var i; - var j; - - N = shape.length; - sh = arr.shape; - M = sh.length; - if ( N < M ) { - throw new Error( format( '0Lx0Z' ) ); - } - // Initialize a strides array... - strides = []; - for ( i = 0; i < N; i++ ) { - strides.push( 0 ); - } - // Determine the output array strides... - st = arr.strides; - for ( i = N-1; i >= 0; i-- ) { - j = M - N + i; - if ( j < 0 ) { - // Prepended singleton dimension; stride is zero... - continue; - } - d = sh[ j ]; - dim = shape[ i ]; - if ( dim !== 0 && dim < d ) { - throw new Error( format( '0Lx5T', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); - } - if ( d === dim ) { - strides[ i ] = st[ j ]; - } else if ( d === 1 ) { - // In order to broadcast dimensions, we set the stride for that dimension to zero... - strides[ i ] = 0; - } else { - // At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when "tiling" an array; e.g., `dim=4` and `d=2`)... - throw new Error( format( '0Lx5U', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); - } - } - return ndarray( arr.dtype, arr.data, copy( shape ), strides, arr.offset, arr.order ); // eslint-disable-line max-len -} - - -// EXPORTS // - -module.exports = broadcastArray; diff --git a/package.json b/package.json index 2c99fad..2be9a19 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.6", "description": "Broadcast an ndarray to a specified 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,38 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-base-ctor": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^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-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", @@ -84,7 +29,6 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..8a4f6aa --- /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 97decdb..0000000 --- a/test/test.js +++ /dev/null @@ -1,511 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 broadcastArray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastArray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a desired shape which has fewer dimensions than 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() { - broadcastArray( 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() { - broadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape and an input array shape 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() { - broadcastArray( x, value ); - }; - } -}); - -tape( 'the function returns a "base" ndarray instance', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = broadcastArray( 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 = broadcastArray( 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.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, 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 = broadcastArray( x, expected ); - - actual = y.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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 5bcd7e0cf1f4127a6fb63b228c8c0985bee3fada Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Jul 2022 16:49:04 +0000 Subject: [PATCH 05/91] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index fca038e..8aa2804 100644 --- a/lib/main.js +++ b/lib/main.js @@ -21,7 +21,7 @@ // MODULES // var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var copy = require( './copy_array.js' ); @@ -98,7 +98,7 @@ function broadcastArray( arr, shape ) { sh = arr.shape; M = sh.length; if ( N < M ) { - throw new Error( 'invalid argument. Cannot broadcast an array to a shape having fewer dimensions. Arrays can only be broadcasted to shapes having the same or more dimensions.' ); + throw new Error( format( '0Lx0Z' ) ); } // Initialize a strides array... strides = []; @@ -116,7 +116,7 @@ function broadcastArray( arr, shape ) { d = sh[ j ]; dim = shape[ i ]; if ( dim !== 0 && dim < d ) { - throw new Error( format( 'invalid argument. Input array cannot be broadcast to the specified shape, as the specified shape has a dimension whose size is less than the size of the corresponding dimension in the input array. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); + throw new Error( format( '0Lx5T', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); } if ( d === dim ) { strides[ i ] = st[ j ]; @@ -125,7 +125,7 @@ function broadcastArray( arr, shape ) { strides[ i ] = 0; } else { // At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when "tiling" an array; e.g., `dim=4` and `d=2`)... - throw new Error( format( 'invalid argument. Input array and the specified shape are broadcast incompatible. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); + throw new Error( format( '0Lx5U', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); } } return ndarray( arr.dtype, arr.data, copy( shape ), strides, arr.offset, arr.order ); // eslint-disable-line max-len diff --git a/package.json b/package.json index 96b6613..2c99fad 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ }, "dependencies": { "@stdlib/ndarray-base-ctor": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x" }, "devDependencies": { From ff23acf07d2e80b5044818703dd6998e04ffe211 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 2 Jul 2022 04:04:34 +0000 Subject: [PATCH 06/91] Remove files --- index.d.ts | 80 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2774 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 a0d0239..0000000 --- a/index.d.ts +++ /dev/null @@ -1,80 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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. -* -* ## Notes -* -* - The function throws an error if a provided ndarray is incompatible with a provided shape. -* - The 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. -* - The returned array is a "base" ndarray, and, thus, the returned array 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 always returns a new ndarray instance even if the input ndarray shape and the desired shape are the same. -* -* @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 -* @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 = broadcastArray( 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 broadcastArray( arr: ndarray, shape: ArrayLike ): ndarray; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = broadcastArray; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index bf09bce..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-ctor@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";function e(r){var t,e;for(t=[],e=0;e=0;l--)if(!((m=a-h+l)<0)){if(j=f[m],0!==(i=n[l])&&i\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction broadcastArray( arr, shape ) {\n\tvar strides;\n\tvar dim;\n\tvar sh;\n\tvar st;\n\tvar N;\n\tvar M;\n\tvar d;\n\tvar i;\n\tvar j;\n\n\tN = shape.length;\n\tsh = arr.shape;\n\tM = sh.length;\n\tif ( N < M ) {\n\t\tthrow new Error( format( '0Lx0Z' ) );\n\t}\n\t// Initialize a strides array...\n\tstrides = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tstrides.push( 0 );\n\t}\n\t// Determine the output array strides...\n\tst = arr.strides;\n\tfor ( i = N-1; i >= 0; i-- ) {\n\t\tj = M - N + i;\n\t\tif ( j < 0 ) {\n\t\t\t// Prepended singleton dimension; stride is zero...\n\t\t\tcontinue;\n\t\t}\n\t\td = sh[ j ];\n\t\tdim = shape[ i ];\n\t\tif ( dim !== 0 && dim < d ) {\n\t\t\tthrow new Error( format( '0Lx5T', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t\tif ( d === dim ) {\n\t\t\tstrides[ i ] = st[ j ];\n\t\t} else if ( d === 1 ) {\n\t\t\t// In order to broadcast dimensions, we set the stride for that dimension to zero...\n\t\t\tstrides[ i ] = 0;\n\t\t} else {\n\t\t\t// At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when \"tiling\" an array; e.g., `dim=4` and `d=2`)...\n\t\t\tthrow new Error( format( '0Lx5U', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t}\n\treturn ndarray( arr.dtype, arr.data, copy( shape ), strides, arr.offset, arr.order ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nexport default broadcastArray;\n"],"names":["copyArray","arr","out","i","length","push","broadcastArray","shape","strides","dim","sh","st","N","M","d","j","Error","format","copy","join","ndarray","dtype","data","offset","order"],"mappings":";;+KAsCA,SAASA,EAAWC,GACnB,IAAIC,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAIF,EAAIG,OAAQD,IAC5BD,EAAIG,KAAMJ,EAAKE,IAEhB,OAAOD,ECuCR,SAASI,EAAgBL,EAAKM,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAX,EACAY,EAKJ,IAHAH,EAAIL,EAAMH,SAEVS,GADAH,EAAKT,EAAIM,OACFH,QAEN,MAAM,IAAIY,MAAOC,EAAQ,UAI1B,IADAT,EAAU,GACJL,EAAI,EAAGA,EAAIS,EAAGT,IACnBK,EAAQH,KAAM,GAIf,IADAM,EAAKV,EAAIO,QACHL,EAAIS,EAAE,EAAGT,GAAK,EAAGA,IAEtB,MADAY,EAAIF,EAAID,EAAIT,GACH,GAAT,CAMA,GAFAW,EAAIJ,EAAIK,GAEK,KADbN,EAAMF,EAAOJ,KACKM,EAAMK,EACvB,MAAM,IAAIE,MAAOC,EAAQ,QAASC,EAAMR,GAAKS,KAAM,MAAQD,EAAMX,GAAQY,KAAM,MAAQhB,IAExF,GAAKW,IAAML,EACVD,EAASL,GAAMQ,EAAII,OACb,IAAW,IAAND,EAKX,MAAM,IAAIE,MAAOC,EAAQ,QAASC,EAAMR,GAAKS,KAAM,MAAQD,EAAMX,GAAQY,KAAM,MAAQhB,IAHvFK,EAASL,GAAM,GAMjB,OAAOiB,EAASnB,EAAIoB,MAAOpB,EAAIqB,KAAMJ,EAAMX,GAASC,EAASP,EAAIsB,OAAQtB,EAAIuB"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 8a4f6aa..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 55a856db6f24b92ebe7d2717fd69cb4e95e0ce65 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 2 Jul 2022 04:05:23 +0000 Subject: [PATCH 07/91] Auto-generated commit --- .editorconfig | 181 -- .eslintrc.js | 1 - .gitattributes | 33 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 681 ------ .github/workflows/publish.yml | 157 -- .github/workflows/test.yml | 92 - .github/workflows/test_bundles.yml | 180 -- .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 178 -- .npmignore | 227 -- .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 ---- README.md | 47 +- benchmark/benchmark.js | 161 -- benchmark/benchmark.ndims.js | 110 - branches.md | 53 - docs/repl.txt | 65 - docs/types/test.ts | 94 - examples/index.js | 49 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/copy_array.js | 53 - lib/index.js | 68 - lib/main.js | 137 -- package.json | 60 +- stats.html | 2689 +++++++++++++++++++++ test/test.js | 511 ---- 39 files changed, 2717 insertions(+), 4236 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 (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/copy_array.js 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 86dd854..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-07-01T01:32:19.145Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 6c59584..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-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 9a95c7d..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-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 + + ```
@@ -164,7 +157,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]. @@ -224,11 +217,11 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-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 7983cf3..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,161 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 broadcastArray = 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 = broadcastArray( 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', 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 = broadcastArray( 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', 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 = broadcastArray( 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(); -}); diff --git a/benchmark/benchmark.ndims.js b/benchmark/benchmark.ndims.js deleted file mode 100644 index 141a816..0000000 --- a/benchmark/benchmark.ndims.js +++ /dev/null @@ -1,110 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 broadcastArray = 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 = broadcastArray( 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 1aef646..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-array" -click B href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/main" -click C href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/production" -click D href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-array -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-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 db0f44c..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,65 +0,0 @@ - -{{alias}}( arr, shape ) - Broadcasts an ndarray to a specified shape. - - The 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. - - The returned array is a "base" ndarray, and, thus, the returned array 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. - - The function always returns a new ndarray instance even if the input ndarray - shape and the desired shape are the same. - - 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 4041dc7..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,94 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 broadcastArray = 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(); - - broadcastArray( x, [ 2, 2, 2 ] ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is not provided a first argument which is an ndarray... -{ - broadcastArray( '5', [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( 5, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( true, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( false, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( null, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( {}, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( [ '5' ], [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( ( 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(); - - broadcastArray( x, '5' ); // $ExpectError - broadcastArray( x, 5 ); // $ExpectError - broadcastArray( x, true ); // $ExpectError - broadcastArray( x, false ); // $ExpectError - broadcastArray( x, null ); // $ExpectError - broadcastArray( x, {} ); // $ExpectError - broadcastArray( x, [ '5' ] ); // $ExpectError - broadcastArray( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - - broadcastArray(); // $ExpectError - broadcastArray( x ); // $ExpectError - broadcastArray( x, [ 1, 2, 3 ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index f0dc7b6..0000000 --- a/examples/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 broadcastArray = require( './../lib' ); - -// Create a 2x2 array: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -// returns - -// Broadcast the array to 3x2x2: -var y = broadcastArray( 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 sub; -var v; -var i; -for ( i = 0; i < N; i++ ) { - v = y.iget( i ); - sub = ind2sub( sh, i ); - console.log( 'Y[%s] = %d', sub.join( ', ' ), v ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index f8117ef..a0d0239 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..bf09bce --- /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-ctor@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";function e(r){var t,e;for(t=[],e=0;e=0;l--)if(!((m=a-h+l)<0)){if(j=f[m],0!==(i=n[l])&&i\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction broadcastArray( arr, shape ) {\n\tvar strides;\n\tvar dim;\n\tvar sh;\n\tvar st;\n\tvar N;\n\tvar M;\n\tvar d;\n\tvar i;\n\tvar j;\n\n\tN = shape.length;\n\tsh = arr.shape;\n\tM = sh.length;\n\tif ( N < M ) {\n\t\tthrow new Error( format( '0Lx0Z' ) );\n\t}\n\t// Initialize a strides array...\n\tstrides = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tstrides.push( 0 );\n\t}\n\t// Determine the output array strides...\n\tst = arr.strides;\n\tfor ( i = N-1; i >= 0; i-- ) {\n\t\tj = M - N + i;\n\t\tif ( j < 0 ) {\n\t\t\t// Prepended singleton dimension; stride is zero...\n\t\t\tcontinue;\n\t\t}\n\t\td = sh[ j ];\n\t\tdim = shape[ i ];\n\t\tif ( dim !== 0 && dim < d ) {\n\t\t\tthrow new Error( format( '0Lx5T', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t\tif ( d === dim ) {\n\t\t\tstrides[ i ] = st[ j ];\n\t\t} else if ( d === 1 ) {\n\t\t\t// In order to broadcast dimensions, we set the stride for that dimension to zero...\n\t\t\tstrides[ i ] = 0;\n\t\t} else {\n\t\t\t// At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when \"tiling\" an array; e.g., `dim=4` and `d=2`)...\n\t\t\tthrow new Error( format( '0Lx5U', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t}\n\treturn ndarray( arr.dtype, arr.data, copy( shape ), strides, arr.offset, arr.order ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nexport default broadcastArray;\n"],"names":["copyArray","arr","out","i","length","push","broadcastArray","shape","strides","dim","sh","st","N","M","d","j","Error","format","copy","join","ndarray","dtype","data","offset","order"],"mappings":";;+KAsCA,SAASA,EAAWC,GACnB,IAAIC,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAIF,EAAIG,OAAQD,IAC5BD,EAAIG,KAAMJ,EAAKE,IAEhB,OAAOD,ECuCR,SAASI,EAAgBL,EAAKM,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAX,EACAY,EAKJ,IAHAH,EAAIL,EAAMH,SAEVS,GADAH,EAAKT,EAAIM,OACFH,QAEN,MAAM,IAAIY,MAAOC,EAAQ,UAI1B,IADAT,EAAU,GACJL,EAAI,EAAGA,EAAIS,EAAGT,IACnBK,EAAQH,KAAM,GAIf,IADAM,EAAKV,EAAIO,QACHL,EAAIS,EAAE,EAAGT,GAAK,EAAGA,IAEtB,MADAY,EAAIF,EAAID,EAAIT,GACH,GAAT,CAMA,GAFAW,EAAIJ,EAAIK,GAEK,KADbN,EAAMF,EAAOJ,KACKM,EAAMK,EACvB,MAAM,IAAIE,MAAOC,EAAQ,QAASC,EAAMR,GAAKS,KAAM,MAAQD,EAAMX,GAAQY,KAAM,MAAQhB,IAExF,GAAKW,IAAML,EACVD,EAASL,GAAMQ,EAAII,OACb,IAAW,IAAND,EAKX,MAAM,IAAIE,MAAOC,EAAQ,QAASC,EAAMR,GAAKS,KAAM,MAAQD,EAAMX,GAAQY,KAAM,MAAQhB,IAHvFK,EAASL,GAAM,GAMjB,OAAOiB,EAASnB,EAAIoB,MAAOpB,EAAIqB,KAAMJ,EAAMX,GAASC,EAASP,EAAIsB,OAAQtB,EAAIuB"} \ No newline at end of file diff --git a/lib/copy_array.js b/lib/copy_array.js deleted file mode 100644 index 6c9a427..0000000 --- a/lib/copy_array.js +++ /dev/null @@ -1,53 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN / - -/** -* Copies an array-like object to an array. -* -* @private -* @param {ArrayLikeObject} arr - input array -* @returns {Array} output array -* -* @example -* var arr = [ 1, 2, 3 ]; -* -* var out = copyArray( arr ); -* // returns [ 1, 2, 3 ] -* -* var bool = ( out === arr ); -* // returns false -*/ -function copyArray( arr ) { - var out; - var i; - - out = []; - for ( i = 0; i < arr.length; i++ ) { - out.push( arr[ i ] ); - } - return out; -} - - -// EXPORTS // - -module.exports = copyArray; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index b6aaa86..0000000 --- a/lib/index.js +++ /dev/null @@ -1,68 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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. -* -* @module @stdlib/ndarray-base-broadcast-array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var broadcastArray = require( '@stdlib/ndarray-base-broadcast-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = broadcastArray( 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 8aa2804..0000000 --- a/lib/main.js +++ /dev/null @@ -1,137 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var copy = require( './copy_array.js' ); - - -// MAIN // - -/** -* Broadcasts an ndarray to a specified shape. -* -* ## Notes -* -* - The 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. -* -* @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 = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] ); -* // throws -*/ -function broadcastArray( arr, shape ) { - var strides; - var dim; - var sh; - var st; - var N; - var M; - var d; - var i; - var j; - - N = shape.length; - sh = arr.shape; - M = sh.length; - if ( N < M ) { - throw new Error( format( '0Lx0Z' ) ); - } - // Initialize a strides array... - strides = []; - for ( i = 0; i < N; i++ ) { - strides.push( 0 ); - } - // Determine the output array strides... - st = arr.strides; - for ( i = N-1; i >= 0; i-- ) { - j = M - N + i; - if ( j < 0 ) { - // Prepended singleton dimension; stride is zero... - continue; - } - d = sh[ j ]; - dim = shape[ i ]; - if ( dim !== 0 && dim < d ) { - throw new Error( format( '0Lx5T', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); - } - if ( d === dim ) { - strides[ i ] = st[ j ]; - } else if ( d === 1 ) { - // In order to broadcast dimensions, we set the stride for that dimension to zero... - strides[ i ] = 0; - } else { - // At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when "tiling" an array; e.g., `dim=4` and `d=2`)... - throw new Error( format( '0Lx5U', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); - } - } - return ndarray( arr.dtype, arr.data, copy( shape ), strides, arr.offset, arr.order ); // eslint-disable-line max-len -} - - -// EXPORTS // - -module.exports = broadcastArray; diff --git a/package.json b/package.json index 2c99fad..2be9a19 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.6", "description": "Broadcast an ndarray to a specified 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,38 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-base-ctor": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^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-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", @@ -84,7 +29,6 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..87e3f82 --- /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 97decdb..0000000 --- a/test/test.js +++ /dev/null @@ -1,511 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 broadcastArray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastArray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a desired shape which has fewer dimensions than 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() { - broadcastArray( 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() { - broadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape and an input array shape 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() { - broadcastArray( x, value ); - }; - } -}); - -tape( 'the function returns a "base" ndarray instance', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = broadcastArray( 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 = broadcastArray( 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.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, 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 = broadcastArray( x, expected ); - - actual = y.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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 8676a3111f60f0fbe83a31f02df189c6b1b1a8a1 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 6 Jul 2022 18:41:42 +0000 Subject: [PATCH 08/91] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index fca038e..8aa2804 100644 --- a/lib/main.js +++ b/lib/main.js @@ -21,7 +21,7 @@ // MODULES // var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var copy = require( './copy_array.js' ); @@ -98,7 +98,7 @@ function broadcastArray( arr, shape ) { sh = arr.shape; M = sh.length; if ( N < M ) { - throw new Error( 'invalid argument. Cannot broadcast an array to a shape having fewer dimensions. Arrays can only be broadcasted to shapes having the same or more dimensions.' ); + throw new Error( format( '0Lx0Z' ) ); } // Initialize a strides array... strides = []; @@ -116,7 +116,7 @@ function broadcastArray( arr, shape ) { d = sh[ j ]; dim = shape[ i ]; if ( dim !== 0 && dim < d ) { - throw new Error( format( 'invalid argument. Input array cannot be broadcast to the specified shape, as the specified shape has a dimension whose size is less than the size of the corresponding dimension in the input array. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); + throw new Error( format( '0Lx5T', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); } if ( d === dim ) { strides[ i ] = st[ j ]; @@ -125,7 +125,7 @@ function broadcastArray( arr, shape ) { strides[ i ] = 0; } else { // At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when "tiling" an array; e.g., `dim=4` and `d=2`)... - throw new Error( format( 'invalid argument. Input array and the specified shape are broadcast incompatible. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); + throw new Error( format( '0Lx5U', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); } } return ndarray( arr.dtype, arr.data, copy( shape ), strides, arr.offset, arr.order ); // eslint-disable-line max-len diff --git a/package.json b/package.json index 96b6613..2c99fad 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ }, "dependencies": { "@stdlib/ndarray-base-ctor": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x" }, "devDependencies": { From e397afacf0908e9bb20b73d987fea084a2adc851 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 6 Jul 2022 18:55:55 +0000 Subject: [PATCH 09/91] Remove files --- index.d.ts | 80 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2774 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 a0d0239..0000000 --- a/index.d.ts +++ /dev/null @@ -1,80 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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. -* -* ## Notes -* -* - The function throws an error if a provided ndarray is incompatible with a provided shape. -* - The 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. -* - The returned array is a "base" ndarray, and, thus, the returned array 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 always returns a new ndarray instance even if the input ndarray shape and the desired shape are the same. -* -* @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 -* @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 = broadcastArray( 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 broadcastArray( arr: ndarray, shape: ArrayLike ): ndarray; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = broadcastArray; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index bf09bce..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-ctor@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";function e(r){var t,e;for(t=[],e=0;e=0;l--)if(!((m=a-h+l)<0)){if(j=f[m],0!==(i=n[l])&&i\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction broadcastArray( arr, shape ) {\n\tvar strides;\n\tvar dim;\n\tvar sh;\n\tvar st;\n\tvar N;\n\tvar M;\n\tvar d;\n\tvar i;\n\tvar j;\n\n\tN = shape.length;\n\tsh = arr.shape;\n\tM = sh.length;\n\tif ( N < M ) {\n\t\tthrow new Error( format( '0Lx0Z' ) );\n\t}\n\t// Initialize a strides array...\n\tstrides = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tstrides.push( 0 );\n\t}\n\t// Determine the output array strides...\n\tst = arr.strides;\n\tfor ( i = N-1; i >= 0; i-- ) {\n\t\tj = M - N + i;\n\t\tif ( j < 0 ) {\n\t\t\t// Prepended singleton dimension; stride is zero...\n\t\t\tcontinue;\n\t\t}\n\t\td = sh[ j ];\n\t\tdim = shape[ i ];\n\t\tif ( dim !== 0 && dim < d ) {\n\t\t\tthrow new Error( format( '0Lx5T', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t\tif ( d === dim ) {\n\t\t\tstrides[ i ] = st[ j ];\n\t\t} else if ( d === 1 ) {\n\t\t\t// In order to broadcast dimensions, we set the stride for that dimension to zero...\n\t\t\tstrides[ i ] = 0;\n\t\t} else {\n\t\t\t// At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when \"tiling\" an array; e.g., `dim=4` and `d=2`)...\n\t\t\tthrow new Error( format( '0Lx5U', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t}\n\treturn ndarray( arr.dtype, arr.data, copy( shape ), strides, arr.offset, arr.order ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nexport default broadcastArray;\n"],"names":["copyArray","arr","out","i","length","push","broadcastArray","shape","strides","dim","sh","st","N","M","d","j","Error","format","copy","join","ndarray","dtype","data","offset","order"],"mappings":";;+KAsCA,SAASA,EAAWC,GACnB,IAAIC,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAIF,EAAIG,OAAQD,IAC5BD,EAAIG,KAAMJ,EAAKE,IAEhB,OAAOD,ECuCR,SAASI,EAAgBL,EAAKM,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAX,EACAY,EAKJ,IAHAH,EAAIL,EAAMH,SAEVS,GADAH,EAAKT,EAAIM,OACFH,QAEN,MAAM,IAAIY,MAAOC,EAAQ,UAI1B,IADAT,EAAU,GACJL,EAAI,EAAGA,EAAIS,EAAGT,IACnBK,EAAQH,KAAM,GAIf,IADAM,EAAKV,EAAIO,QACHL,EAAIS,EAAE,EAAGT,GAAK,EAAGA,IAEtB,MADAY,EAAIF,EAAID,EAAIT,GACH,GAAT,CAMA,GAFAW,EAAIJ,EAAIK,GAEK,KADbN,EAAMF,EAAOJ,KACKM,EAAMK,EACvB,MAAM,IAAIE,MAAOC,EAAQ,QAASC,EAAMR,GAAKS,KAAM,MAAQD,EAAMX,GAAQY,KAAM,MAAQhB,IAExF,GAAKW,IAAML,EACVD,EAASL,GAAMQ,EAAII,OACb,IAAW,IAAND,EAKX,MAAM,IAAIE,MAAOC,EAAQ,QAASC,EAAMR,GAAKS,KAAM,MAAQD,EAAMX,GAAQY,KAAM,MAAQhB,IAHvFK,EAASL,GAAM,GAMjB,OAAOiB,EAASnB,EAAIoB,MAAOpB,EAAIqB,KAAMJ,EAAMX,GAASC,EAASP,EAAIsB,OAAQtB,EAAIuB"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 87e3f82..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 4495293fd2ae348ed981a828a5b97b8d3c63d2b1 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 6 Jul 2022 18:57:45 +0000 Subject: [PATCH 10/91] Auto-generated commit --- .editorconfig | 181 -- .eslintrc.js | 1 - .gitattributes | 33 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 687 ------ .github/workflows/publish.yml | 117 - .github/workflows/test.yml | 92 - .github/workflows/test_bundles.yml | 180 -- .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 178 -- .npmignore | 227 -- .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 ---- README.md | 47 +- benchmark/benchmark.js | 161 -- benchmark/benchmark.ndims.js | 110 - branches.md | 53 - docs/repl.txt | 65 - docs/types/test.ts | 94 - examples/index.js | 49 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/copy_array.js | 53 - lib/index.js | 68 - lib/main.js | 137 -- package.json | 60 +- stats.html | 2689 +++++++++++++++++++++ test/test.js | 511 ---- 38 files changed, 2717 insertions(+), 4201 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 (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/copy_array.js 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 6c59584..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-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 9a95c7d..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-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 + + ```
@@ -164,7 +157,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]. @@ -224,11 +217,11 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-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 7983cf3..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,161 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 broadcastArray = 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 = broadcastArray( 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', 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 = broadcastArray( 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', 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 = broadcastArray( 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(); -}); diff --git a/benchmark/benchmark.ndims.js b/benchmark/benchmark.ndims.js deleted file mode 100644 index 141a816..0000000 --- a/benchmark/benchmark.ndims.js +++ /dev/null @@ -1,110 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 broadcastArray = 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 = broadcastArray( 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 1aef646..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-array" -click B href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/main" -click C href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/production" -click D href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-array -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-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 db0f44c..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,65 +0,0 @@ - -{{alias}}( arr, shape ) - Broadcasts an ndarray to a specified shape. - - The 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. - - The returned array is a "base" ndarray, and, thus, the returned array 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. - - The function always returns a new ndarray instance even if the input ndarray - shape and the desired shape are the same. - - 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 4041dc7..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,94 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 broadcastArray = 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(); - - broadcastArray( x, [ 2, 2, 2 ] ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is not provided a first argument which is an ndarray... -{ - broadcastArray( '5', [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( 5, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( true, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( false, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( null, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( {}, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( [ '5' ], [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( ( 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(); - - broadcastArray( x, '5' ); // $ExpectError - broadcastArray( x, 5 ); // $ExpectError - broadcastArray( x, true ); // $ExpectError - broadcastArray( x, false ); // $ExpectError - broadcastArray( x, null ); // $ExpectError - broadcastArray( x, {} ); // $ExpectError - broadcastArray( x, [ '5' ] ); // $ExpectError - broadcastArray( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - - broadcastArray(); // $ExpectError - broadcastArray( x ); // $ExpectError - broadcastArray( x, [ 1, 2, 3 ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index f0dc7b6..0000000 --- a/examples/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 broadcastArray = require( './../lib' ); - -// Create a 2x2 array: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -// returns - -// Broadcast the array to 3x2x2: -var y = broadcastArray( 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 sub; -var v; -var i; -for ( i = 0; i < N; i++ ) { - v = y.iget( i ); - sub = ind2sub( sh, i ); - console.log( 'Y[%s] = %d', sub.join( ', ' ), v ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index f8117ef..a0d0239 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..bf09bce --- /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-ctor@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";function e(r){var t,e;for(t=[],e=0;e=0;l--)if(!((m=a-h+l)<0)){if(j=f[m],0!==(i=n[l])&&i\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction broadcastArray( arr, shape ) {\n\tvar strides;\n\tvar dim;\n\tvar sh;\n\tvar st;\n\tvar N;\n\tvar M;\n\tvar d;\n\tvar i;\n\tvar j;\n\n\tN = shape.length;\n\tsh = arr.shape;\n\tM = sh.length;\n\tif ( N < M ) {\n\t\tthrow new Error( format( '0Lx0Z' ) );\n\t}\n\t// Initialize a strides array...\n\tstrides = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tstrides.push( 0 );\n\t}\n\t// Determine the output array strides...\n\tst = arr.strides;\n\tfor ( i = N-1; i >= 0; i-- ) {\n\t\tj = M - N + i;\n\t\tif ( j < 0 ) {\n\t\t\t// Prepended singleton dimension; stride is zero...\n\t\t\tcontinue;\n\t\t}\n\t\td = sh[ j ];\n\t\tdim = shape[ i ];\n\t\tif ( dim !== 0 && dim < d ) {\n\t\t\tthrow new Error( format( '0Lx5T', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t\tif ( d === dim ) {\n\t\t\tstrides[ i ] = st[ j ];\n\t\t} else if ( d === 1 ) {\n\t\t\t// In order to broadcast dimensions, we set the stride for that dimension to zero...\n\t\t\tstrides[ i ] = 0;\n\t\t} else {\n\t\t\t// At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when \"tiling\" an array; e.g., `dim=4` and `d=2`)...\n\t\t\tthrow new Error( format( '0Lx5U', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t}\n\treturn ndarray( arr.dtype, arr.data, copy( shape ), strides, arr.offset, arr.order ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nexport default broadcastArray;\n"],"names":["copyArray","arr","out","i","length","push","broadcastArray","shape","strides","dim","sh","st","N","M","d","j","Error","format","copy","join","ndarray","dtype","data","offset","order"],"mappings":";;+KAsCA,SAASA,EAAWC,GACnB,IAAIC,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAIF,EAAIG,OAAQD,IAC5BD,EAAIG,KAAMJ,EAAKE,IAEhB,OAAOD,ECuCR,SAASI,EAAgBL,EAAKM,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAX,EACAY,EAKJ,IAHAH,EAAIL,EAAMH,SAEVS,GADAH,EAAKT,EAAIM,OACFH,QAEN,MAAM,IAAIY,MAAOC,EAAQ,UAI1B,IADAT,EAAU,GACJL,EAAI,EAAGA,EAAIS,EAAGT,IACnBK,EAAQH,KAAM,GAIf,IADAM,EAAKV,EAAIO,QACHL,EAAIS,EAAE,EAAGT,GAAK,EAAGA,IAEtB,MADAY,EAAIF,EAAID,EAAIT,GACH,GAAT,CAMA,GAFAW,EAAIJ,EAAIK,GAEK,KADbN,EAAMF,EAAOJ,KACKM,EAAMK,EACvB,MAAM,IAAIE,MAAOC,EAAQ,QAASC,EAAMR,GAAKS,KAAM,MAAQD,EAAMX,GAAQY,KAAM,MAAQhB,IAExF,GAAKW,IAAML,EACVD,EAASL,GAAMQ,EAAII,OACb,IAAW,IAAND,EAKX,MAAM,IAAIE,MAAOC,EAAQ,QAASC,EAAMR,GAAKS,KAAM,MAAQD,EAAMX,GAAQY,KAAM,MAAQhB,IAHvFK,EAASL,GAAM,GAMjB,OAAOiB,EAASnB,EAAIoB,MAAOpB,EAAIqB,KAAMJ,EAAMX,GAASC,EAASP,EAAIsB,OAAQtB,EAAIuB"} \ No newline at end of file diff --git a/lib/copy_array.js b/lib/copy_array.js deleted file mode 100644 index 6c9a427..0000000 --- a/lib/copy_array.js +++ /dev/null @@ -1,53 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN / - -/** -* Copies an array-like object to an array. -* -* @private -* @param {ArrayLikeObject} arr - input array -* @returns {Array} output array -* -* @example -* var arr = [ 1, 2, 3 ]; -* -* var out = copyArray( arr ); -* // returns [ 1, 2, 3 ] -* -* var bool = ( out === arr ); -* // returns false -*/ -function copyArray( arr ) { - var out; - var i; - - out = []; - for ( i = 0; i < arr.length; i++ ) { - out.push( arr[ i ] ); - } - return out; -} - - -// EXPORTS // - -module.exports = copyArray; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index b6aaa86..0000000 --- a/lib/index.js +++ /dev/null @@ -1,68 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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. -* -* @module @stdlib/ndarray-base-broadcast-array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var broadcastArray = require( '@stdlib/ndarray-base-broadcast-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = broadcastArray( 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 8aa2804..0000000 --- a/lib/main.js +++ /dev/null @@ -1,137 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var copy = require( './copy_array.js' ); - - -// MAIN // - -/** -* Broadcasts an ndarray to a specified shape. -* -* ## Notes -* -* - The 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. -* -* @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 = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] ); -* // throws -*/ -function broadcastArray( arr, shape ) { - var strides; - var dim; - var sh; - var st; - var N; - var M; - var d; - var i; - var j; - - N = shape.length; - sh = arr.shape; - M = sh.length; - if ( N < M ) { - throw new Error( format( '0Lx0Z' ) ); - } - // Initialize a strides array... - strides = []; - for ( i = 0; i < N; i++ ) { - strides.push( 0 ); - } - // Determine the output array strides... - st = arr.strides; - for ( i = N-1; i >= 0; i-- ) { - j = M - N + i; - if ( j < 0 ) { - // Prepended singleton dimension; stride is zero... - continue; - } - d = sh[ j ]; - dim = shape[ i ]; - if ( dim !== 0 && dim < d ) { - throw new Error( format( '0Lx5T', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); - } - if ( d === dim ) { - strides[ i ] = st[ j ]; - } else if ( d === 1 ) { - // In order to broadcast dimensions, we set the stride for that dimension to zero... - strides[ i ] = 0; - } else { - // At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when "tiling" an array; e.g., `dim=4` and `d=2`)... - throw new Error( format( '0Lx5U', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); - } - } - return ndarray( arr.dtype, arr.data, copy( shape ), strides, arr.offset, arr.order ); // eslint-disable-line max-len -} - - -// EXPORTS // - -module.exports = broadcastArray; diff --git a/package.json b/package.json index 2c99fad..2be9a19 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.6", "description": "Broadcast an ndarray to a specified 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,38 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-base-ctor": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^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-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", @@ -84,7 +29,6 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..fdc34e0 --- /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 97decdb..0000000 --- a/test/test.js +++ /dev/null @@ -1,511 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 broadcastArray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastArray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a desired shape which has fewer dimensions than 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() { - broadcastArray( 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() { - broadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape and an input array shape 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() { - broadcastArray( x, value ); - }; - } -}); - -tape( 'the function returns a "base" ndarray instance', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = broadcastArray( 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 = broadcastArray( 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.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, 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 = broadcastArray( x, expected ); - - actual = y.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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 7cd39d6c662876d698c11c6a4c2e3fbcdd54500d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Aug 2022 03:54:39 +0000 Subject: [PATCH 11/91] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index fca038e..8aa2804 100644 --- a/lib/main.js +++ b/lib/main.js @@ -21,7 +21,7 @@ // MODULES // var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var copy = require( './copy_array.js' ); @@ -98,7 +98,7 @@ function broadcastArray( arr, shape ) { sh = arr.shape; M = sh.length; if ( N < M ) { - throw new Error( 'invalid argument. Cannot broadcast an array to a shape having fewer dimensions. Arrays can only be broadcasted to shapes having the same or more dimensions.' ); + throw new Error( format( '0Lx0Z' ) ); } // Initialize a strides array... strides = []; @@ -116,7 +116,7 @@ function broadcastArray( arr, shape ) { d = sh[ j ]; dim = shape[ i ]; if ( dim !== 0 && dim < d ) { - throw new Error( format( 'invalid argument. Input array cannot be broadcast to the specified shape, as the specified shape has a dimension whose size is less than the size of the corresponding dimension in the input array. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); + throw new Error( format( '0Lx5T', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); } if ( d === dim ) { strides[ i ] = st[ j ]; @@ -125,7 +125,7 @@ function broadcastArray( arr, shape ) { strides[ i ] = 0; } else { // At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when "tiling" an array; e.g., `dim=4` and `d=2`)... - throw new Error( format( 'invalid argument. Input array and the specified shape are broadcast incompatible. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); + throw new Error( format( '0Lx5U', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); } } return ndarray( arr.dtype, arr.data, copy( shape ), strides, arr.offset, arr.order ); // eslint-disable-line max-len diff --git a/package.json b/package.json index 96b6613..2c99fad 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ }, "dependencies": { "@stdlib/ndarray-base-ctor": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x" }, "devDependencies": { From bb53da1f0a4b929b30f9c1165e14e24d191455a9 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Aug 2022 17:58:31 +0000 Subject: [PATCH 12/91] Remove files --- index.d.ts | 80 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2774 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 a0d0239..0000000 --- a/index.d.ts +++ /dev/null @@ -1,80 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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. -* -* ## Notes -* -* - The function throws an error if a provided ndarray is incompatible with a provided shape. -* - The 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. -* - The returned array is a "base" ndarray, and, thus, the returned array 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 always returns a new ndarray instance even if the input ndarray shape and the desired shape are the same. -* -* @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 -* @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 = broadcastArray( 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 broadcastArray( arr: ndarray, shape: ArrayLike ): ndarray; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = broadcastArray; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index bf09bce..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-ctor@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";function e(r){var t,e;for(t=[],e=0;e=0;l--)if(!((m=a-h+l)<0)){if(j=f[m],0!==(i=n[l])&&i\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction broadcastArray( arr, shape ) {\n\tvar strides;\n\tvar dim;\n\tvar sh;\n\tvar st;\n\tvar N;\n\tvar M;\n\tvar d;\n\tvar i;\n\tvar j;\n\n\tN = shape.length;\n\tsh = arr.shape;\n\tM = sh.length;\n\tif ( N < M ) {\n\t\tthrow new Error( format( '0Lx0Z' ) );\n\t}\n\t// Initialize a strides array...\n\tstrides = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tstrides.push( 0 );\n\t}\n\t// Determine the output array strides...\n\tst = arr.strides;\n\tfor ( i = N-1; i >= 0; i-- ) {\n\t\tj = M - N + i;\n\t\tif ( j < 0 ) {\n\t\t\t// Prepended singleton dimension; stride is zero...\n\t\t\tcontinue;\n\t\t}\n\t\td = sh[ j ];\n\t\tdim = shape[ i ];\n\t\tif ( dim !== 0 && dim < d ) {\n\t\t\tthrow new Error( format( '0Lx5T', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t\tif ( d === dim ) {\n\t\t\tstrides[ i ] = st[ j ];\n\t\t} else if ( d === 1 ) {\n\t\t\t// In order to broadcast dimensions, we set the stride for that dimension to zero...\n\t\t\tstrides[ i ] = 0;\n\t\t} else {\n\t\t\t// At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when \"tiling\" an array; e.g., `dim=4` and `d=2`)...\n\t\t\tthrow new Error( format( '0Lx5U', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t}\n\treturn ndarray( arr.dtype, arr.data, copy( shape ), strides, arr.offset, arr.order ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nexport default broadcastArray;\n"],"names":["copyArray","arr","out","i","length","push","broadcastArray","shape","strides","dim","sh","st","N","M","d","j","Error","format","copy","join","ndarray","dtype","data","offset","order"],"mappings":";;+KAsCA,SAASA,EAAWC,GACnB,IAAIC,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAIF,EAAIG,OAAQD,IAC5BD,EAAIG,KAAMJ,EAAKE,IAEhB,OAAOD,ECuCR,SAASI,EAAgBL,EAAKM,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAX,EACAY,EAKJ,IAHAH,EAAIL,EAAMH,SAEVS,GADAH,EAAKT,EAAIM,OACFH,QAEN,MAAM,IAAIY,MAAOC,EAAQ,UAI1B,IADAT,EAAU,GACJL,EAAI,EAAGA,EAAIS,EAAGT,IACnBK,EAAQH,KAAM,GAIf,IADAM,EAAKV,EAAIO,QACHL,EAAIS,EAAE,EAAGT,GAAK,EAAGA,IAEtB,MADAY,EAAIF,EAAID,EAAIT,GACH,GAAT,CAMA,GAFAW,EAAIJ,EAAIK,GAEK,KADbN,EAAMF,EAAOJ,KACKM,EAAMK,EACvB,MAAM,IAAIE,MAAOC,EAAQ,QAASC,EAAMR,GAAKS,KAAM,MAAQD,EAAMX,GAAQY,KAAM,MAAQhB,IAExF,GAAKW,IAAML,EACVD,EAASL,GAAMQ,EAAII,OACb,IAAW,IAAND,EAKX,MAAM,IAAIE,MAAOC,EAAQ,QAASC,EAAMR,GAAKS,KAAM,MAAQD,EAAMX,GAAQY,KAAM,MAAQhB,IAHvFK,EAASL,GAAM,GAMjB,OAAOiB,EAASnB,EAAIoB,MAAOpB,EAAIqB,KAAMJ,EAAMX,GAASC,EAASP,EAAIsB,OAAQtB,EAAIuB"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index fdc34e0..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From f898c7f351bdacbae65b670f282dc2d657bb782b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Aug 2022 17:59:33 +0000 Subject: [PATCH 13/91] Auto-generated commit --- .editorconfig | 181 -- .eslintrc.js | 1 - .gitattributes | 33 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 760 ------ .github/workflows/publish.yml | 117 - .github/workflows/test.yml | 92 - .github/workflows/test_bundles.yml | 180 -- .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 178 -- .npmignore | 227 -- .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 ---- README.md | 47 +- benchmark/benchmark.js | 161 -- benchmark/benchmark.ndims.js | 110 - branches.md | 53 - docs/repl.txt | 65 - docs/types/test.ts | 94 - examples/index.js | 49 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/copy_array.js | 53 - lib/index.js | 68 - lib/main.js | 137 -- package.json | 60 +- stats.html | 2689 +++++++++++++++++++++ test/test.js | 511 ---- 39 files changed, 2717 insertions(+), 4275 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 (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/copy_array.js 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 c434d97..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-08-01T01:34:56.675Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 6c59584..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-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 9a95c7d..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-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 + + ```
@@ -164,7 +157,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]. @@ -224,11 +217,11 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-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 7983cf3..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,161 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 broadcastArray = 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 = broadcastArray( 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', 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 = broadcastArray( 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', 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 = broadcastArray( 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(); -}); diff --git a/benchmark/benchmark.ndims.js b/benchmark/benchmark.ndims.js deleted file mode 100644 index 141a816..0000000 --- a/benchmark/benchmark.ndims.js +++ /dev/null @@ -1,110 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 broadcastArray = 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 = broadcastArray( 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 1aef646..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-array" -click B href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/main" -click C href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/production" -click D href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-array -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-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 db0f44c..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,65 +0,0 @@ - -{{alias}}( arr, shape ) - Broadcasts an ndarray to a specified shape. - - The 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. - - The returned array is a "base" ndarray, and, thus, the returned array 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. - - The function always returns a new ndarray instance even if the input ndarray - shape and the desired shape are the same. - - 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 4041dc7..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,94 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 broadcastArray = 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(); - - broadcastArray( x, [ 2, 2, 2 ] ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is not provided a first argument which is an ndarray... -{ - broadcastArray( '5', [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( 5, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( true, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( false, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( null, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( {}, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( [ '5' ], [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( ( 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(); - - broadcastArray( x, '5' ); // $ExpectError - broadcastArray( x, 5 ); // $ExpectError - broadcastArray( x, true ); // $ExpectError - broadcastArray( x, false ); // $ExpectError - broadcastArray( x, null ); // $ExpectError - broadcastArray( x, {} ); // $ExpectError - broadcastArray( x, [ '5' ] ); // $ExpectError - broadcastArray( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - - broadcastArray(); // $ExpectError - broadcastArray( x ); // $ExpectError - broadcastArray( x, [ 1, 2, 3 ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index f0dc7b6..0000000 --- a/examples/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 broadcastArray = require( './../lib' ); - -// Create a 2x2 array: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -// returns - -// Broadcast the array to 3x2x2: -var y = broadcastArray( 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 sub; -var v; -var i; -for ( i = 0; i < N; i++ ) { - v = y.iget( i ); - sub = ind2sub( sh, i ); - console.log( 'Y[%s] = %d', sub.join( ', ' ), v ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index f8117ef..a0d0239 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..02a38d0 --- /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-ctor@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function e(r){var t,e;for(t=[],e=0;e=0;l--)if(!((m=a-h+l)<0)){if(j=f[m],0!==(i=n[l])&&i\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction broadcastArray( arr, shape ) {\n\tvar strides;\n\tvar dim;\n\tvar sh;\n\tvar st;\n\tvar N;\n\tvar M;\n\tvar d;\n\tvar i;\n\tvar j;\n\n\tN = shape.length;\n\tsh = arr.shape;\n\tM = sh.length;\n\tif ( N < M ) {\n\t\tthrow new Error( format( '0Lx0Z' ) );\n\t}\n\t// Initialize a strides array...\n\tstrides = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tstrides.push( 0 );\n\t}\n\t// Determine the output array strides...\n\tst = arr.strides;\n\tfor ( i = N-1; i >= 0; i-- ) {\n\t\tj = M - N + i;\n\t\tif ( j < 0 ) {\n\t\t\t// Prepended singleton dimension; stride is zero...\n\t\t\tcontinue;\n\t\t}\n\t\td = sh[ j ];\n\t\tdim = shape[ i ];\n\t\tif ( dim !== 0 && dim < d ) {\n\t\t\tthrow new Error( format( '0Lx5T', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t\tif ( d === dim ) {\n\t\t\tstrides[ i ] = st[ j ];\n\t\t} else if ( d === 1 ) {\n\t\t\t// In order to broadcast dimensions, we set the stride for that dimension to zero...\n\t\t\tstrides[ i ] = 0;\n\t\t} else {\n\t\t\t// At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when \"tiling\" an array; e.g., `dim=4` and `d=2`)...\n\t\t\tthrow new Error( format( '0Lx5U', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t}\n\treturn ndarray( arr.dtype, arr.data, copy( shape ), strides, arr.offset, arr.order ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nexport default broadcastArray;\n"],"names":["copyArray","arr","out","i","length","push","broadcastArray","shape","strides","dim","sh","st","N","M","d","j","Error","format","copy","join","ndarray","dtype","data","offset","order"],"mappings":";;sLAsCA,SAASA,EAAWC,GACnB,IAAIC,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAIF,EAAIG,OAAQD,IAC5BD,EAAIG,KAAMJ,EAAKE,IAEhB,OAAOD,ECuCR,SAASI,EAAgBL,EAAKM,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAX,EACAY,EAKJ,IAHAH,EAAIL,EAAMH,SAEVS,GADAH,EAAKT,EAAIM,OACFH,QAEN,MAAM,IAAIY,MAAOC,EAAQ,UAI1B,IADAT,EAAU,GACJL,EAAI,EAAGA,EAAIS,EAAGT,IACnBK,EAAQH,KAAM,GAIf,IADAM,EAAKV,EAAIO,QACHL,EAAIS,EAAE,EAAGT,GAAK,EAAGA,IAEtB,MADAY,EAAIF,EAAID,EAAIT,GACH,GAAT,CAMA,GAFAW,EAAIJ,EAAIK,GAEK,KADbN,EAAMF,EAAOJ,KACKM,EAAMK,EACvB,MAAM,IAAIE,MAAOC,EAAQ,QAASC,EAAMR,GAAKS,KAAM,MAAQD,EAAMX,GAAQY,KAAM,MAAQhB,IAExF,GAAKW,IAAML,EACVD,EAASL,GAAMQ,EAAII,OACb,IAAW,IAAND,EAKX,MAAM,IAAIE,MAAOC,EAAQ,QAASC,EAAMR,GAAKS,KAAM,MAAQD,EAAMX,GAAQY,KAAM,MAAQhB,IAHvFK,EAASL,GAAM,GAMjB,OAAOiB,EAASnB,EAAIoB,MAAOpB,EAAIqB,KAAMJ,EAAMX,GAASC,EAASP,EAAIsB,OAAQtB,EAAIuB"} \ No newline at end of file diff --git a/lib/copy_array.js b/lib/copy_array.js deleted file mode 100644 index 6c9a427..0000000 --- a/lib/copy_array.js +++ /dev/null @@ -1,53 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN / - -/** -* Copies an array-like object to an array. -* -* @private -* @param {ArrayLikeObject} arr - input array -* @returns {Array} output array -* -* @example -* var arr = [ 1, 2, 3 ]; -* -* var out = copyArray( arr ); -* // returns [ 1, 2, 3 ] -* -* var bool = ( out === arr ); -* // returns false -*/ -function copyArray( arr ) { - var out; - var i; - - out = []; - for ( i = 0; i < arr.length; i++ ) { - out.push( arr[ i ] ); - } - return out; -} - - -// EXPORTS // - -module.exports = copyArray; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index b6aaa86..0000000 --- a/lib/index.js +++ /dev/null @@ -1,68 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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. -* -* @module @stdlib/ndarray-base-broadcast-array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var broadcastArray = require( '@stdlib/ndarray-base-broadcast-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = broadcastArray( 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 8aa2804..0000000 --- a/lib/main.js +++ /dev/null @@ -1,137 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var copy = require( './copy_array.js' ); - - -// MAIN // - -/** -* Broadcasts an ndarray to a specified shape. -* -* ## Notes -* -* - The 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. -* -* @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 = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] ); -* // throws -*/ -function broadcastArray( arr, shape ) { - var strides; - var dim; - var sh; - var st; - var N; - var M; - var d; - var i; - var j; - - N = shape.length; - sh = arr.shape; - M = sh.length; - if ( N < M ) { - throw new Error( format( '0Lx0Z' ) ); - } - // Initialize a strides array... - strides = []; - for ( i = 0; i < N; i++ ) { - strides.push( 0 ); - } - // Determine the output array strides... - st = arr.strides; - for ( i = N-1; i >= 0; i-- ) { - j = M - N + i; - if ( j < 0 ) { - // Prepended singleton dimension; stride is zero... - continue; - } - d = sh[ j ]; - dim = shape[ i ]; - if ( dim !== 0 && dim < d ) { - throw new Error( format( '0Lx5T', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); - } - if ( d === dim ) { - strides[ i ] = st[ j ]; - } else if ( d === 1 ) { - // In order to broadcast dimensions, we set the stride for that dimension to zero... - strides[ i ] = 0; - } else { - // At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when "tiling" an array; e.g., `dim=4` and `d=2`)... - throw new Error( format( '0Lx5U', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); - } - } - return ndarray( arr.dtype, arr.data, copy( shape ), strides, arr.offset, arr.order ); // eslint-disable-line max-len -} - - -// EXPORTS // - -module.exports = broadcastArray; diff --git a/package.json b/package.json index 2c99fad..2be9a19 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.6", "description": "Broadcast an ndarray to a specified 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,38 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-base-ctor": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^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-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", @@ -84,7 +29,6 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..e72d141 --- /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 97decdb..0000000 --- a/test/test.js +++ /dev/null @@ -1,511 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 broadcastArray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastArray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a desired shape which has fewer dimensions than 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() { - broadcastArray( 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() { - broadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape and an input array shape 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() { - broadcastArray( x, value ); - }; - } -}); - -tape( 'the function returns a "base" ndarray instance', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = broadcastArray( 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 = broadcastArray( 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.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, 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 = broadcastArray( x, expected ); - - actual = y.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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 2ca1c5455369725b455e137c84eba0b09ee63906 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Sep 2022 03:45:10 +0000 Subject: [PATCH 14/91] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index fca038e..8aa2804 100644 --- a/lib/main.js +++ b/lib/main.js @@ -21,7 +21,7 @@ // MODULES // var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var copy = require( './copy_array.js' ); @@ -98,7 +98,7 @@ function broadcastArray( arr, shape ) { sh = arr.shape; M = sh.length; if ( N < M ) { - throw new Error( 'invalid argument. Cannot broadcast an array to a shape having fewer dimensions. Arrays can only be broadcasted to shapes having the same or more dimensions.' ); + throw new Error( format( '0Lx0Z' ) ); } // Initialize a strides array... strides = []; @@ -116,7 +116,7 @@ function broadcastArray( arr, shape ) { d = sh[ j ]; dim = shape[ i ]; if ( dim !== 0 && dim < d ) { - throw new Error( format( 'invalid argument. Input array cannot be broadcast to the specified shape, as the specified shape has a dimension whose size is less than the size of the corresponding dimension in the input array. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); + throw new Error( format( '0Lx5T', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); } if ( d === dim ) { strides[ i ] = st[ j ]; @@ -125,7 +125,7 @@ function broadcastArray( arr, shape ) { strides[ i ] = 0; } else { // At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when "tiling" an array; e.g., `dim=4` and `d=2`)... - throw new Error( format( 'invalid argument. Input array and the specified shape are broadcast incompatible. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); + throw new Error( format( '0Lx5U', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); } } return ndarray( arr.dtype, arr.data, copy( shape ), strides, arr.offset, arr.order ); // eslint-disable-line max-len diff --git a/package.json b/package.json index 96b6613..2c99fad 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ }, "dependencies": { "@stdlib/ndarray-base-ctor": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x" }, "devDependencies": { From 4388b39ebf3124d9984ab7c3a3148a47d5b48fbc Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Sep 2022 14:03:19 +0000 Subject: [PATCH 15/91] Remove files --- index.d.ts | 80 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2774 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 a0d0239..0000000 --- a/index.d.ts +++ /dev/null @@ -1,80 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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. -* -* ## Notes -* -* - The function throws an error if a provided ndarray is incompatible with a provided shape. -* - The 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. -* - The returned array is a "base" ndarray, and, thus, the returned array 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 always returns a new ndarray instance even if the input ndarray shape and the desired shape are the same. -* -* @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 -* @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 = broadcastArray( 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 broadcastArray( arr: ndarray, shape: ArrayLike ): ndarray; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = broadcastArray; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 02a38d0..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-ctor@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function e(r){var t,e;for(t=[],e=0;e=0;l--)if(!((m=a-h+l)<0)){if(j=f[m],0!==(i=n[l])&&i\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction broadcastArray( arr, shape ) {\n\tvar strides;\n\tvar dim;\n\tvar sh;\n\tvar st;\n\tvar N;\n\tvar M;\n\tvar d;\n\tvar i;\n\tvar j;\n\n\tN = shape.length;\n\tsh = arr.shape;\n\tM = sh.length;\n\tif ( N < M ) {\n\t\tthrow new Error( format( '0Lx0Z' ) );\n\t}\n\t// Initialize a strides array...\n\tstrides = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tstrides.push( 0 );\n\t}\n\t// Determine the output array strides...\n\tst = arr.strides;\n\tfor ( i = N-1; i >= 0; i-- ) {\n\t\tj = M - N + i;\n\t\tif ( j < 0 ) {\n\t\t\t// Prepended singleton dimension; stride is zero...\n\t\t\tcontinue;\n\t\t}\n\t\td = sh[ j ];\n\t\tdim = shape[ i ];\n\t\tif ( dim !== 0 && dim < d ) {\n\t\t\tthrow new Error( format( '0Lx5T', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t\tif ( d === dim ) {\n\t\t\tstrides[ i ] = st[ j ];\n\t\t} else if ( d === 1 ) {\n\t\t\t// In order to broadcast dimensions, we set the stride for that dimension to zero...\n\t\t\tstrides[ i ] = 0;\n\t\t} else {\n\t\t\t// At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when \"tiling\" an array; e.g., `dim=4` and `d=2`)...\n\t\t\tthrow new Error( format( '0Lx5U', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t}\n\treturn ndarray( arr.dtype, arr.data, copy( shape ), strides, arr.offset, arr.order ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nexport default broadcastArray;\n"],"names":["copyArray","arr","out","i","length","push","broadcastArray","shape","strides","dim","sh","st","N","M","d","j","Error","format","copy","join","ndarray","dtype","data","offset","order"],"mappings":";;sLAsCA,SAASA,EAAWC,GACnB,IAAIC,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAIF,EAAIG,OAAQD,IAC5BD,EAAIG,KAAMJ,EAAKE,IAEhB,OAAOD,ECuCR,SAASI,EAAgBL,EAAKM,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAX,EACAY,EAKJ,IAHAH,EAAIL,EAAMH,SAEVS,GADAH,EAAKT,EAAIM,OACFH,QAEN,MAAM,IAAIY,MAAOC,EAAQ,UAI1B,IADAT,EAAU,GACJL,EAAI,EAAGA,EAAIS,EAAGT,IACnBK,EAAQH,KAAM,GAIf,IADAM,EAAKV,EAAIO,QACHL,EAAIS,EAAE,EAAGT,GAAK,EAAGA,IAEtB,MADAY,EAAIF,EAAID,EAAIT,GACH,GAAT,CAMA,GAFAW,EAAIJ,EAAIK,GAEK,KADbN,EAAMF,EAAOJ,KACKM,EAAMK,EACvB,MAAM,IAAIE,MAAOC,EAAQ,QAASC,EAAMR,GAAKS,KAAM,MAAQD,EAAMX,GAAQY,KAAM,MAAQhB,IAExF,GAAKW,IAAML,EACVD,EAASL,GAAMQ,EAAII,OACb,IAAW,IAAND,EAKX,MAAM,IAAIE,MAAOC,EAAQ,QAASC,EAAMR,GAAKS,KAAM,MAAQD,EAAMX,GAAQY,KAAM,MAAQhB,IAHvFK,EAASL,GAAM,GAMjB,OAAOiB,EAASnB,EAAIoB,MAAOpB,EAAIqB,KAAMJ,EAAMX,GAASC,EAASP,EAAIsB,OAAQtB,EAAIuB"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index e72d141..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From d538757aa372654346f5cca953c002ea44ff6644 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Sep 2022 14:04:15 +0000 Subject: [PATCH 16/91] Auto-generated commit --- .editorconfig | 181 -- .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 760 ------ .github/workflows/publish.yml | 117 - .github/workflows/test.yml | 92 - .github/workflows/test_bundles.yml | 180 -- .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 178 -- .npmignore | 227 -- .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 ---- README.md | 47 +- benchmark/benchmark.js | 161 -- benchmark/benchmark.ndims.js | 110 - branches.md | 53 - docs/repl.txt | 65 - docs/types/test.ts | 94 - examples/index.js | 49 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/copy_array.js | 53 - lib/index.js | 68 - lib/main.js | 137 -- package.json | 60 +- stats.html | 2689 +++++++++++++++++++++ test/test.js | 511 ---- 39 files changed, 2717 insertions(+), 4291 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 (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/copy_array.js 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 22527a5..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-09-01T01:34:10.527Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 6c59584..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-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 9a95c7d..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-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 + + ```
@@ -164,7 +157,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]. @@ -224,11 +217,11 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-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 7983cf3..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,161 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 broadcastArray = 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 = broadcastArray( 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', 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 = broadcastArray( 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', 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 = broadcastArray( 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(); -}); diff --git a/benchmark/benchmark.ndims.js b/benchmark/benchmark.ndims.js deleted file mode 100644 index 141a816..0000000 --- a/benchmark/benchmark.ndims.js +++ /dev/null @@ -1,110 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 broadcastArray = 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 = broadcastArray( 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 1aef646..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-array" -click B href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/main" -click C href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/production" -click D href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-array -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-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 db0f44c..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,65 +0,0 @@ - -{{alias}}( arr, shape ) - Broadcasts an ndarray to a specified shape. - - The 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. - - The returned array is a "base" ndarray, and, thus, the returned array 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. - - The function always returns a new ndarray instance even if the input ndarray - shape and the desired shape are the same. - - 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 4041dc7..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,94 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 broadcastArray = 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(); - - broadcastArray( x, [ 2, 2, 2 ] ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is not provided a first argument which is an ndarray... -{ - broadcastArray( '5', [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( 5, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( true, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( false, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( null, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( {}, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( [ '5' ], [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( ( 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(); - - broadcastArray( x, '5' ); // $ExpectError - broadcastArray( x, 5 ); // $ExpectError - broadcastArray( x, true ); // $ExpectError - broadcastArray( x, false ); // $ExpectError - broadcastArray( x, null ); // $ExpectError - broadcastArray( x, {} ); // $ExpectError - broadcastArray( x, [ '5' ] ); // $ExpectError - broadcastArray( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - - broadcastArray(); // $ExpectError - broadcastArray( x ); // $ExpectError - broadcastArray( x, [ 1, 2, 3 ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index f0dc7b6..0000000 --- a/examples/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 broadcastArray = require( './../lib' ); - -// Create a 2x2 array: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -// returns - -// Broadcast the array to 3x2x2: -var y = broadcastArray( 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 sub; -var v; -var i; -for ( i = 0; i < N; i++ ) { - v = y.iget( i ); - sub = ind2sub( sh, i ); - console.log( 'Y[%s] = %d', sub.join( ', ' ), v ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index f8117ef..a0d0239 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..02a38d0 --- /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-ctor@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function e(r){var t,e;for(t=[],e=0;e=0;l--)if(!((m=a-h+l)<0)){if(j=f[m],0!==(i=n[l])&&i\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction broadcastArray( arr, shape ) {\n\tvar strides;\n\tvar dim;\n\tvar sh;\n\tvar st;\n\tvar N;\n\tvar M;\n\tvar d;\n\tvar i;\n\tvar j;\n\n\tN = shape.length;\n\tsh = arr.shape;\n\tM = sh.length;\n\tif ( N < M ) {\n\t\tthrow new Error( format( '0Lx0Z' ) );\n\t}\n\t// Initialize a strides array...\n\tstrides = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tstrides.push( 0 );\n\t}\n\t// Determine the output array strides...\n\tst = arr.strides;\n\tfor ( i = N-1; i >= 0; i-- ) {\n\t\tj = M - N + i;\n\t\tif ( j < 0 ) {\n\t\t\t// Prepended singleton dimension; stride is zero...\n\t\t\tcontinue;\n\t\t}\n\t\td = sh[ j ];\n\t\tdim = shape[ i ];\n\t\tif ( dim !== 0 && dim < d ) {\n\t\t\tthrow new Error( format( '0Lx5T', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t\tif ( d === dim ) {\n\t\t\tstrides[ i ] = st[ j ];\n\t\t} else if ( d === 1 ) {\n\t\t\t// In order to broadcast dimensions, we set the stride for that dimension to zero...\n\t\t\tstrides[ i ] = 0;\n\t\t} else {\n\t\t\t// At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when \"tiling\" an array; e.g., `dim=4` and `d=2`)...\n\t\t\tthrow new Error( format( '0Lx5U', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t}\n\treturn ndarray( arr.dtype, arr.data, copy( shape ), strides, arr.offset, arr.order ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nexport default broadcastArray;\n"],"names":["copyArray","arr","out","i","length","push","broadcastArray","shape","strides","dim","sh","st","N","M","d","j","Error","format","copy","join","ndarray","dtype","data","offset","order"],"mappings":";;sLAsCA,SAASA,EAAWC,GACnB,IAAIC,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAIF,EAAIG,OAAQD,IAC5BD,EAAIG,KAAMJ,EAAKE,IAEhB,OAAOD,ECuCR,SAASI,EAAgBL,EAAKM,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAX,EACAY,EAKJ,IAHAH,EAAIL,EAAMH,SAEVS,GADAH,EAAKT,EAAIM,OACFH,QAEN,MAAM,IAAIY,MAAOC,EAAQ,UAI1B,IADAT,EAAU,GACJL,EAAI,EAAGA,EAAIS,EAAGT,IACnBK,EAAQH,KAAM,GAIf,IADAM,EAAKV,EAAIO,QACHL,EAAIS,EAAE,EAAGT,GAAK,EAAGA,IAEtB,MADAY,EAAIF,EAAID,EAAIT,GACH,GAAT,CAMA,GAFAW,EAAIJ,EAAIK,GAEK,KADbN,EAAMF,EAAOJ,KACKM,EAAMK,EACvB,MAAM,IAAIE,MAAOC,EAAQ,QAASC,EAAMR,GAAKS,KAAM,MAAQD,EAAMX,GAAQY,KAAM,MAAQhB,IAExF,GAAKW,IAAML,EACVD,EAASL,GAAMQ,EAAII,OACb,IAAW,IAAND,EAKX,MAAM,IAAIE,MAAOC,EAAQ,QAASC,EAAMR,GAAKS,KAAM,MAAQD,EAAMX,GAAQY,KAAM,MAAQhB,IAHvFK,EAASL,GAAM,GAMjB,OAAOiB,EAASnB,EAAIoB,MAAOpB,EAAIqB,KAAMJ,EAAMX,GAASC,EAASP,EAAIsB,OAAQtB,EAAIuB"} \ No newline at end of file diff --git a/lib/copy_array.js b/lib/copy_array.js deleted file mode 100644 index 6c9a427..0000000 --- a/lib/copy_array.js +++ /dev/null @@ -1,53 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN / - -/** -* Copies an array-like object to an array. -* -* @private -* @param {ArrayLikeObject} arr - input array -* @returns {Array} output array -* -* @example -* var arr = [ 1, 2, 3 ]; -* -* var out = copyArray( arr ); -* // returns [ 1, 2, 3 ] -* -* var bool = ( out === arr ); -* // returns false -*/ -function copyArray( arr ) { - var out; - var i; - - out = []; - for ( i = 0; i < arr.length; i++ ) { - out.push( arr[ i ] ); - } - return out; -} - - -// EXPORTS // - -module.exports = copyArray; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index b6aaa86..0000000 --- a/lib/index.js +++ /dev/null @@ -1,68 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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. -* -* @module @stdlib/ndarray-base-broadcast-array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var broadcastArray = require( '@stdlib/ndarray-base-broadcast-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = broadcastArray( 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 8aa2804..0000000 --- a/lib/main.js +++ /dev/null @@ -1,137 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var copy = require( './copy_array.js' ); - - -// MAIN // - -/** -* Broadcasts an ndarray to a specified shape. -* -* ## Notes -* -* - The 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. -* -* @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 = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] ); -* // throws -*/ -function broadcastArray( arr, shape ) { - var strides; - var dim; - var sh; - var st; - var N; - var M; - var d; - var i; - var j; - - N = shape.length; - sh = arr.shape; - M = sh.length; - if ( N < M ) { - throw new Error( format( '0Lx0Z' ) ); - } - // Initialize a strides array... - strides = []; - for ( i = 0; i < N; i++ ) { - strides.push( 0 ); - } - // Determine the output array strides... - st = arr.strides; - for ( i = N-1; i >= 0; i-- ) { - j = M - N + i; - if ( j < 0 ) { - // Prepended singleton dimension; stride is zero... - continue; - } - d = sh[ j ]; - dim = shape[ i ]; - if ( dim !== 0 && dim < d ) { - throw new Error( format( '0Lx5T', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); - } - if ( d === dim ) { - strides[ i ] = st[ j ]; - } else if ( d === 1 ) { - // In order to broadcast dimensions, we set the stride for that dimension to zero... - strides[ i ] = 0; - } else { - // At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when "tiling" an array; e.g., `dim=4` and `d=2`)... - throw new Error( format( '0Lx5U', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); - } - } - return ndarray( arr.dtype, arr.data, copy( shape ), strides, arr.offset, arr.order ); // eslint-disable-line max-len -} - - -// EXPORTS // - -module.exports = broadcastArray; diff --git a/package.json b/package.json index 2c99fad..2be9a19 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.6", "description": "Broadcast an ndarray to a specified 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,38 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-base-ctor": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^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-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", @@ -84,7 +29,6 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..9766c22 --- /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 97decdb..0000000 --- a/test/test.js +++ /dev/null @@ -1,511 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 broadcastArray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastArray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a desired shape which has fewer dimensions than 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() { - broadcastArray( 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() { - broadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape and an input array shape 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() { - broadcastArray( x, value ); - }; - } -}); - -tape( 'the function returns a "base" ndarray instance', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = broadcastArray( 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 = broadcastArray( 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.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, 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 = broadcastArray( x, expected ); - - actual = y.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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 dbc86daab70909000a2a3c161ed98dcd214a30c4 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Oct 2022 04:12:21 +0000 Subject: [PATCH 17/91] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index fca038e..8aa2804 100644 --- a/lib/main.js +++ b/lib/main.js @@ -21,7 +21,7 @@ // MODULES // var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var copy = require( './copy_array.js' ); @@ -98,7 +98,7 @@ function broadcastArray( arr, shape ) { sh = arr.shape; M = sh.length; if ( N < M ) { - throw new Error( 'invalid argument. Cannot broadcast an array to a shape having fewer dimensions. Arrays can only be broadcasted to shapes having the same or more dimensions.' ); + throw new Error( format( '0Lx0Z' ) ); } // Initialize a strides array... strides = []; @@ -116,7 +116,7 @@ function broadcastArray( arr, shape ) { d = sh[ j ]; dim = shape[ i ]; if ( dim !== 0 && dim < d ) { - throw new Error( format( 'invalid argument. Input array cannot be broadcast to the specified shape, as the specified shape has a dimension whose size is less than the size of the corresponding dimension in the input array. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); + throw new Error( format( '0Lx5T', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); } if ( d === dim ) { strides[ i ] = st[ j ]; @@ -125,7 +125,7 @@ function broadcastArray( arr, shape ) { strides[ i ] = 0; } else { // At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when "tiling" an array; e.g., `dim=4` and `d=2`)... - throw new Error( format( 'invalid argument. Input array and the specified shape are broadcast incompatible. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); + throw new Error( format( '0Lx5U', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); } } return ndarray( arr.dtype, arr.data, copy( shape ), strides, arr.offset, arr.order ); // eslint-disable-line max-len diff --git a/package.json b/package.json index 96b6613..2c99fad 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ }, "dependencies": { "@stdlib/ndarray-base-ctor": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x" }, "devDependencies": { From 0dc776121fc614dff710a3fa083375201d7c39eb Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Oct 2022 21:04:10 +0000 Subject: [PATCH 18/91] Remove files --- index.d.ts | 80 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2774 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 a0d0239..0000000 --- a/index.d.ts +++ /dev/null @@ -1,80 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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. -* -* ## Notes -* -* - The function throws an error if a provided ndarray is incompatible with a provided shape. -* - The 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. -* - The returned array is a "base" ndarray, and, thus, the returned array 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 always returns a new ndarray instance even if the input ndarray shape and the desired shape are the same. -* -* @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 -* @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 = broadcastArray( 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 broadcastArray( arr: ndarray, shape: ArrayLike ): ndarray; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = broadcastArray; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 02a38d0..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-ctor@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function e(r){var t,e;for(t=[],e=0;e=0;l--)if(!((m=a-h+l)<0)){if(j=f[m],0!==(i=n[l])&&i\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction broadcastArray( arr, shape ) {\n\tvar strides;\n\tvar dim;\n\tvar sh;\n\tvar st;\n\tvar N;\n\tvar M;\n\tvar d;\n\tvar i;\n\tvar j;\n\n\tN = shape.length;\n\tsh = arr.shape;\n\tM = sh.length;\n\tif ( N < M ) {\n\t\tthrow new Error( format( '0Lx0Z' ) );\n\t}\n\t// Initialize a strides array...\n\tstrides = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tstrides.push( 0 );\n\t}\n\t// Determine the output array strides...\n\tst = arr.strides;\n\tfor ( i = N-1; i >= 0; i-- ) {\n\t\tj = M - N + i;\n\t\tif ( j < 0 ) {\n\t\t\t// Prepended singleton dimension; stride is zero...\n\t\t\tcontinue;\n\t\t}\n\t\td = sh[ j ];\n\t\tdim = shape[ i ];\n\t\tif ( dim !== 0 && dim < d ) {\n\t\t\tthrow new Error( format( '0Lx5T', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t\tif ( d === dim ) {\n\t\t\tstrides[ i ] = st[ j ];\n\t\t} else if ( d === 1 ) {\n\t\t\t// In order to broadcast dimensions, we set the stride for that dimension to zero...\n\t\t\tstrides[ i ] = 0;\n\t\t} else {\n\t\t\t// At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when \"tiling\" an array; e.g., `dim=4` and `d=2`)...\n\t\t\tthrow new Error( format( '0Lx5U', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t}\n\treturn ndarray( arr.dtype, arr.data, copy( shape ), strides, arr.offset, arr.order ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nexport default broadcastArray;\n"],"names":["copyArray","arr","out","i","length","push","broadcastArray","shape","strides","dim","sh","st","N","M","d","j","Error","format","copy","join","ndarray","dtype","data","offset","order"],"mappings":";;sLAsCA,SAASA,EAAWC,GACnB,IAAIC,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAIF,EAAIG,OAAQD,IAC5BD,EAAIG,KAAMJ,EAAKE,IAEhB,OAAOD,ECuCR,SAASI,EAAgBL,EAAKM,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAX,EACAY,EAKJ,IAHAH,EAAIL,EAAMH,SAEVS,GADAH,EAAKT,EAAIM,OACFH,QAEN,MAAM,IAAIY,MAAOC,EAAQ,UAI1B,IADAT,EAAU,GACJL,EAAI,EAAGA,EAAIS,EAAGT,IACnBK,EAAQH,KAAM,GAIf,IADAM,EAAKV,EAAIO,QACHL,EAAIS,EAAE,EAAGT,GAAK,EAAGA,IAEtB,MADAY,EAAIF,EAAID,EAAIT,GACH,GAAT,CAMA,GAFAW,EAAIJ,EAAIK,GAEK,KADbN,EAAMF,EAAOJ,KACKM,EAAMK,EACvB,MAAM,IAAIE,MAAOC,EAAQ,QAASC,EAAMR,GAAKS,KAAM,MAAQD,EAAMX,GAAQY,KAAM,MAAQhB,IAExF,GAAKW,IAAML,EACVD,EAASL,GAAMQ,EAAII,OACb,IAAW,IAAND,EAKX,MAAM,IAAIE,MAAOC,EAAQ,QAASC,EAAMR,GAAKS,KAAM,MAAQD,EAAMX,GAAQY,KAAM,MAAQhB,IAHvFK,EAASL,GAAM,GAMjB,OAAOiB,EAASnB,EAAIoB,MAAOpB,EAAIqB,KAAMJ,EAAMX,GAASC,EAASP,EAAIsB,OAAQtB,EAAIuB"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 9766c22..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From a9811e16cf07c1b095132e478287105dc557782c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Oct 2022 21:04:54 +0000 Subject: [PATCH 19/91] Auto-generated commit --- .editorconfig | 181 -- .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 760 ------ .github/workflows/publish.yml | 117 - .github/workflows/test.yml | 92 - .github/workflows/test_bundles.yml | 180 -- .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 178 -- .npmignore | 227 -- .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 ---- README.md | 47 +- benchmark/benchmark.js | 161 -- benchmark/benchmark.ndims.js | 110 - branches.md | 53 - docs/repl.txt | 65 - docs/types/test.ts | 94 - examples/index.js | 49 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/copy_array.js | 53 - lib/index.js | 68 - lib/main.js | 137 -- package.json | 60 +- stats.html | 2689 +++++++++++++++++++++ test/test.js | 511 ---- 39 files changed, 2717 insertions(+), 4291 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 (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/copy_array.js 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 ff15331..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-10-01T02:01:13.815Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 6c59584..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-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 9a95c7d..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-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 + + ```
@@ -164,7 +157,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]. @@ -224,11 +217,11 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-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 7983cf3..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,161 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 broadcastArray = 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 = broadcastArray( 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', 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 = broadcastArray( 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', 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 = broadcastArray( 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(); -}); diff --git a/benchmark/benchmark.ndims.js b/benchmark/benchmark.ndims.js deleted file mode 100644 index 141a816..0000000 --- a/benchmark/benchmark.ndims.js +++ /dev/null @@ -1,110 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 broadcastArray = 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 = broadcastArray( 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 1aef646..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-array" -click B href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/main" -click C href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/production" -click D href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-array -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-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 db0f44c..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,65 +0,0 @@ - -{{alias}}( arr, shape ) - Broadcasts an ndarray to a specified shape. - - The 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. - - The returned array is a "base" ndarray, and, thus, the returned array 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. - - The function always returns a new ndarray instance even if the input ndarray - shape and the desired shape are the same. - - 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 4041dc7..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,94 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 broadcastArray = 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(); - - broadcastArray( x, [ 2, 2, 2 ] ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is not provided a first argument which is an ndarray... -{ - broadcastArray( '5', [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( 5, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( true, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( false, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( null, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( {}, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( [ '5' ], [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( ( 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(); - - broadcastArray( x, '5' ); // $ExpectError - broadcastArray( x, 5 ); // $ExpectError - broadcastArray( x, true ); // $ExpectError - broadcastArray( x, false ); // $ExpectError - broadcastArray( x, null ); // $ExpectError - broadcastArray( x, {} ); // $ExpectError - broadcastArray( x, [ '5' ] ); // $ExpectError - broadcastArray( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - - broadcastArray(); // $ExpectError - broadcastArray( x ); // $ExpectError - broadcastArray( x, [ 1, 2, 3 ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index f0dc7b6..0000000 --- a/examples/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 broadcastArray = require( './../lib' ); - -// Create a 2x2 array: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -// returns - -// Broadcast the array to 3x2x2: -var y = broadcastArray( 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 sub; -var v; -var i; -for ( i = 0; i < N; i++ ) { - v = y.iget( i ); - sub = ind2sub( sh, i ); - console.log( 'Y[%s] = %d', sub.join( ', ' ), v ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index f8117ef..a0d0239 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..02a38d0 --- /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-ctor@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function e(r){var t,e;for(t=[],e=0;e=0;l--)if(!((m=a-h+l)<0)){if(j=f[m],0!==(i=n[l])&&i\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction broadcastArray( arr, shape ) {\n\tvar strides;\n\tvar dim;\n\tvar sh;\n\tvar st;\n\tvar N;\n\tvar M;\n\tvar d;\n\tvar i;\n\tvar j;\n\n\tN = shape.length;\n\tsh = arr.shape;\n\tM = sh.length;\n\tif ( N < M ) {\n\t\tthrow new Error( format( '0Lx0Z' ) );\n\t}\n\t// Initialize a strides array...\n\tstrides = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tstrides.push( 0 );\n\t}\n\t// Determine the output array strides...\n\tst = arr.strides;\n\tfor ( i = N-1; i >= 0; i-- ) {\n\t\tj = M - N + i;\n\t\tif ( j < 0 ) {\n\t\t\t// Prepended singleton dimension; stride is zero...\n\t\t\tcontinue;\n\t\t}\n\t\td = sh[ j ];\n\t\tdim = shape[ i ];\n\t\tif ( dim !== 0 && dim < d ) {\n\t\t\tthrow new Error( format( '0Lx5T', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t\tif ( d === dim ) {\n\t\t\tstrides[ i ] = st[ j ];\n\t\t} else if ( d === 1 ) {\n\t\t\t// In order to broadcast dimensions, we set the stride for that dimension to zero...\n\t\t\tstrides[ i ] = 0;\n\t\t} else {\n\t\t\t// At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when \"tiling\" an array; e.g., `dim=4` and `d=2`)...\n\t\t\tthrow new Error( format( '0Lx5U', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t}\n\treturn ndarray( arr.dtype, arr.data, copy( shape ), strides, arr.offset, arr.order ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nexport default broadcastArray;\n"],"names":["copyArray","arr","out","i","length","push","broadcastArray","shape","strides","dim","sh","st","N","M","d","j","Error","format","copy","join","ndarray","dtype","data","offset","order"],"mappings":";;sLAsCA,SAASA,EAAWC,GACnB,IAAIC,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAIF,EAAIG,OAAQD,IAC5BD,EAAIG,KAAMJ,EAAKE,IAEhB,OAAOD,ECuCR,SAASI,EAAgBL,EAAKM,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAX,EACAY,EAKJ,IAHAH,EAAIL,EAAMH,SAEVS,GADAH,EAAKT,EAAIM,OACFH,QAEN,MAAM,IAAIY,MAAOC,EAAQ,UAI1B,IADAT,EAAU,GACJL,EAAI,EAAGA,EAAIS,EAAGT,IACnBK,EAAQH,KAAM,GAIf,IADAM,EAAKV,EAAIO,QACHL,EAAIS,EAAE,EAAGT,GAAK,EAAGA,IAEtB,MADAY,EAAIF,EAAID,EAAIT,GACH,GAAT,CAMA,GAFAW,EAAIJ,EAAIK,GAEK,KADbN,EAAMF,EAAOJ,KACKM,EAAMK,EACvB,MAAM,IAAIE,MAAOC,EAAQ,QAASC,EAAMR,GAAKS,KAAM,MAAQD,EAAMX,GAAQY,KAAM,MAAQhB,IAExF,GAAKW,IAAML,EACVD,EAASL,GAAMQ,EAAII,OACb,IAAW,IAAND,EAKX,MAAM,IAAIE,MAAOC,EAAQ,QAASC,EAAMR,GAAKS,KAAM,MAAQD,EAAMX,GAAQY,KAAM,MAAQhB,IAHvFK,EAASL,GAAM,GAMjB,OAAOiB,EAASnB,EAAIoB,MAAOpB,EAAIqB,KAAMJ,EAAMX,GAASC,EAASP,EAAIsB,OAAQtB,EAAIuB"} \ No newline at end of file diff --git a/lib/copy_array.js b/lib/copy_array.js deleted file mode 100644 index 6c9a427..0000000 --- a/lib/copy_array.js +++ /dev/null @@ -1,53 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN / - -/** -* Copies an array-like object to an array. -* -* @private -* @param {ArrayLikeObject} arr - input array -* @returns {Array} output array -* -* @example -* var arr = [ 1, 2, 3 ]; -* -* var out = copyArray( arr ); -* // returns [ 1, 2, 3 ] -* -* var bool = ( out === arr ); -* // returns false -*/ -function copyArray( arr ) { - var out; - var i; - - out = []; - for ( i = 0; i < arr.length; i++ ) { - out.push( arr[ i ] ); - } - return out; -} - - -// EXPORTS // - -module.exports = copyArray; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index b6aaa86..0000000 --- a/lib/index.js +++ /dev/null @@ -1,68 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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. -* -* @module @stdlib/ndarray-base-broadcast-array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var broadcastArray = require( '@stdlib/ndarray-base-broadcast-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = broadcastArray( 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 8aa2804..0000000 --- a/lib/main.js +++ /dev/null @@ -1,137 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var copy = require( './copy_array.js' ); - - -// MAIN // - -/** -* Broadcasts an ndarray to a specified shape. -* -* ## Notes -* -* - The 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. -* -* @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 = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] ); -* // throws -*/ -function broadcastArray( arr, shape ) { - var strides; - var dim; - var sh; - var st; - var N; - var M; - var d; - var i; - var j; - - N = shape.length; - sh = arr.shape; - M = sh.length; - if ( N < M ) { - throw new Error( format( '0Lx0Z' ) ); - } - // Initialize a strides array... - strides = []; - for ( i = 0; i < N; i++ ) { - strides.push( 0 ); - } - // Determine the output array strides... - st = arr.strides; - for ( i = N-1; i >= 0; i-- ) { - j = M - N + i; - if ( j < 0 ) { - // Prepended singleton dimension; stride is zero... - continue; - } - d = sh[ j ]; - dim = shape[ i ]; - if ( dim !== 0 && dim < d ) { - throw new Error( format( '0Lx5T', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); - } - if ( d === dim ) { - strides[ i ] = st[ j ]; - } else if ( d === 1 ) { - // In order to broadcast dimensions, we set the stride for that dimension to zero... - strides[ i ] = 0; - } else { - // At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when "tiling" an array; e.g., `dim=4` and `d=2`)... - throw new Error( format( '0Lx5U', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); - } - } - return ndarray( arr.dtype, arr.data, copy( shape ), strides, arr.offset, arr.order ); // eslint-disable-line max-len -} - - -// EXPORTS // - -module.exports = broadcastArray; diff --git a/package.json b/package.json index 2c99fad..2be9a19 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.6", "description": "Broadcast an ndarray to a specified 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,38 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-base-ctor": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^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-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", @@ -84,7 +29,6 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..d3c6fe8 --- /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 97decdb..0000000 --- a/test/test.js +++ /dev/null @@ -1,511 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 broadcastArray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastArray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a desired shape which has fewer dimensions than 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() { - broadcastArray( 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() { - broadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape and an input array shape 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() { - broadcastArray( x, value ); - }; - } -}); - -tape( 'the function returns a "base" ndarray instance', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = broadcastArray( 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 = broadcastArray( 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.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, 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 = broadcastArray( x, expected ); - - actual = y.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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 a399bd23a937cefa2c66016f4226ac952016285f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Nov 2022 01:50:21 +0000 Subject: [PATCH 20/91] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index fca038e..8aa2804 100644 --- a/lib/main.js +++ b/lib/main.js @@ -21,7 +21,7 @@ // MODULES // var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var copy = require( './copy_array.js' ); @@ -98,7 +98,7 @@ function broadcastArray( arr, shape ) { sh = arr.shape; M = sh.length; if ( N < M ) { - throw new Error( 'invalid argument. Cannot broadcast an array to a shape having fewer dimensions. Arrays can only be broadcasted to shapes having the same or more dimensions.' ); + throw new Error( format( '0Lx0Z' ) ); } // Initialize a strides array... strides = []; @@ -116,7 +116,7 @@ function broadcastArray( arr, shape ) { d = sh[ j ]; dim = shape[ i ]; if ( dim !== 0 && dim < d ) { - throw new Error( format( 'invalid argument. Input array cannot be broadcast to the specified shape, as the specified shape has a dimension whose size is less than the size of the corresponding dimension in the input array. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); + throw new Error( format( '0Lx5T', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); } if ( d === dim ) { strides[ i ] = st[ j ]; @@ -125,7 +125,7 @@ function broadcastArray( arr, shape ) { strides[ i ] = 0; } else { // At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when "tiling" an array; e.g., `dim=4` and `d=2`)... - throw new Error( format( 'invalid argument. Input array and the specified shape are broadcast incompatible. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); + throw new Error( format( '0Lx5U', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); } } return ndarray( arr.dtype, arr.data, copy( shape ), strides, arr.offset, arr.order ); // eslint-disable-line max-len diff --git a/package.json b/package.json index 96b6613..2c99fad 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ }, "dependencies": { "@stdlib/ndarray-base-ctor": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x" }, "devDependencies": { From 2efa788e203529c841884f4c3a70587fff18d84a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Nov 2022 14:56:06 +0000 Subject: [PATCH 21/91] Remove files --- index.d.ts | 80 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2774 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 a0d0239..0000000 --- a/index.d.ts +++ /dev/null @@ -1,80 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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. -* -* ## Notes -* -* - The function throws an error if a provided ndarray is incompatible with a provided shape. -* - The 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. -* - The returned array is a "base" ndarray, and, thus, the returned array 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 always returns a new ndarray instance even if the input ndarray shape and the desired shape are the same. -* -* @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 -* @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 = broadcastArray( 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 broadcastArray( arr: ndarray, shape: ArrayLike ): ndarray; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = broadcastArray; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 02a38d0..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-ctor@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function e(r){var t,e;for(t=[],e=0;e=0;l--)if(!((m=a-h+l)<0)){if(j=f[m],0!==(i=n[l])&&i\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction broadcastArray( arr, shape ) {\n\tvar strides;\n\tvar dim;\n\tvar sh;\n\tvar st;\n\tvar N;\n\tvar M;\n\tvar d;\n\tvar i;\n\tvar j;\n\n\tN = shape.length;\n\tsh = arr.shape;\n\tM = sh.length;\n\tif ( N < M ) {\n\t\tthrow new Error( format( '0Lx0Z' ) );\n\t}\n\t// Initialize a strides array...\n\tstrides = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tstrides.push( 0 );\n\t}\n\t// Determine the output array strides...\n\tst = arr.strides;\n\tfor ( i = N-1; i >= 0; i-- ) {\n\t\tj = M - N + i;\n\t\tif ( j < 0 ) {\n\t\t\t// Prepended singleton dimension; stride is zero...\n\t\t\tcontinue;\n\t\t}\n\t\td = sh[ j ];\n\t\tdim = shape[ i ];\n\t\tif ( dim !== 0 && dim < d ) {\n\t\t\tthrow new Error( format( '0Lx5T', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t\tif ( d === dim ) {\n\t\t\tstrides[ i ] = st[ j ];\n\t\t} else if ( d === 1 ) {\n\t\t\t// In order to broadcast dimensions, we set the stride for that dimension to zero...\n\t\t\tstrides[ i ] = 0;\n\t\t} else {\n\t\t\t// At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when \"tiling\" an array; e.g., `dim=4` and `d=2`)...\n\t\t\tthrow new Error( format( '0Lx5U', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t}\n\treturn ndarray( arr.dtype, arr.data, copy( shape ), strides, arr.offset, arr.order ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nexport default broadcastArray;\n"],"names":["copyArray","arr","out","i","length","push","broadcastArray","shape","strides","dim","sh","st","N","M","d","j","Error","format","copy","join","ndarray","dtype","data","offset","order"],"mappings":";;sLAsCA,SAASA,EAAWC,GACnB,IAAIC,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAIF,EAAIG,OAAQD,IAC5BD,EAAIG,KAAMJ,EAAKE,IAEhB,OAAOD,ECuCR,SAASI,EAAgBL,EAAKM,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAX,EACAY,EAKJ,IAHAH,EAAIL,EAAMH,SAEVS,GADAH,EAAKT,EAAIM,OACFH,QAEN,MAAM,IAAIY,MAAOC,EAAQ,UAI1B,IADAT,EAAU,GACJL,EAAI,EAAGA,EAAIS,EAAGT,IACnBK,EAAQH,KAAM,GAIf,IADAM,EAAKV,EAAIO,QACHL,EAAIS,EAAE,EAAGT,GAAK,EAAGA,IAEtB,MADAY,EAAIF,EAAID,EAAIT,GACH,GAAT,CAMA,GAFAW,EAAIJ,EAAIK,GAEK,KADbN,EAAMF,EAAOJ,KACKM,EAAMK,EACvB,MAAM,IAAIE,MAAOC,EAAQ,QAASC,EAAMR,GAAKS,KAAM,MAAQD,EAAMX,GAAQY,KAAM,MAAQhB,IAExF,GAAKW,IAAML,EACVD,EAASL,GAAMQ,EAAII,OACb,IAAW,IAAND,EAKX,MAAM,IAAIE,MAAOC,EAAQ,QAASC,EAAMR,GAAKS,KAAM,MAAQD,EAAMX,GAAQY,KAAM,MAAQhB,IAHvFK,EAASL,GAAM,GAMjB,OAAOiB,EAASnB,EAAIoB,MAAOpB,EAAIqB,KAAMJ,EAAMX,GAASC,EAASP,EAAIsB,OAAQtB,EAAIuB"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index d3c6fe8..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 5657b7e2bf98ea92aadf96b9858bcffcbb218f2c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Nov 2022 14:56:59 +0000 Subject: [PATCH 22/91] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 760 ---- .github/workflows/publish.yml | 117 - .github/workflows/test.yml | 92 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 178 - .npmignore | 227 -- .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 47 +- benchmark/benchmark.js | 161 - benchmark/benchmark.ndims.js | 110 - branches.md | 53 - docs/repl.txt | 65 - docs/types/test.ts | 94 - examples/index.js | 49 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/copy_array.js | 53 - lib/index.js | 68 - lib/main.js | 137 - package.json | 60 +- stats.html | 4044 +++++++++++++++++++++ test/test.js | 511 --- 39 files changed, 4072 insertions(+), 4291 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 (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/copy_array.js 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 5f213d8..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-11-01T01:47:27.719Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 6c59584..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-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 9a95c7d..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-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 16cec43..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: '28 4 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 9113bfe..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,760 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -164,7 +157,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]. @@ -224,11 +217,11 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-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 7983cf3..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,161 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 broadcastArray = 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 = broadcastArray( 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', 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 = broadcastArray( 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', 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 = broadcastArray( 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(); -}); diff --git a/benchmark/benchmark.ndims.js b/benchmark/benchmark.ndims.js deleted file mode 100644 index 141a816..0000000 --- a/benchmark/benchmark.ndims.js +++ /dev/null @@ -1,110 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 broadcastArray = 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 = broadcastArray( 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 1aef646..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-array" -click B href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/main" -click C href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/production" -click D href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-array -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-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 db0f44c..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,65 +0,0 @@ - -{{alias}}( arr, shape ) - Broadcasts an ndarray to a specified shape. - - The 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. - - The returned array is a "base" ndarray, and, thus, the returned array 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. - - The function always returns a new ndarray instance even if the input ndarray - shape and the desired shape are the same. - - 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 4041dc7..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,94 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 broadcastArray = 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(); - - broadcastArray( x, [ 2, 2, 2 ] ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is not provided a first argument which is an ndarray... -{ - broadcastArray( '5', [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( 5, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( true, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( false, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( null, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( {}, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( [ '5' ], [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( ( 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(); - - broadcastArray( x, '5' ); // $ExpectError - broadcastArray( x, 5 ); // $ExpectError - broadcastArray( x, true ); // $ExpectError - broadcastArray( x, false ); // $ExpectError - broadcastArray( x, null ); // $ExpectError - broadcastArray( x, {} ); // $ExpectError - broadcastArray( x, [ '5' ] ); // $ExpectError - broadcastArray( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - - broadcastArray(); // $ExpectError - broadcastArray( x ); // $ExpectError - broadcastArray( x, [ 1, 2, 3 ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index f0dc7b6..0000000 --- a/examples/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 broadcastArray = require( './../lib' ); - -// Create a 2x2 array: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -// returns - -// Broadcast the array to 3x2x2: -var y = broadcastArray( 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 sub; -var v; -var i; -for ( i = 0; i < N; i++ ) { - v = y.iget( i ); - sub = ind2sub( sh, i ); - console.log( 'Y[%s] = %d', sub.join( ', ' ), v ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index f8117ef..a0d0239 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..02a38d0 --- /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-ctor@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function e(r){var t,e;for(t=[],e=0;e=0;l--)if(!((m=a-h+l)<0)){if(j=f[m],0!==(i=n[l])&&i\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction broadcastArray( arr, shape ) {\n\tvar strides;\n\tvar dim;\n\tvar sh;\n\tvar st;\n\tvar N;\n\tvar M;\n\tvar d;\n\tvar i;\n\tvar j;\n\n\tN = shape.length;\n\tsh = arr.shape;\n\tM = sh.length;\n\tif ( N < M ) {\n\t\tthrow new Error( format( '0Lx0Z' ) );\n\t}\n\t// Initialize a strides array...\n\tstrides = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tstrides.push( 0 );\n\t}\n\t// Determine the output array strides...\n\tst = arr.strides;\n\tfor ( i = N-1; i >= 0; i-- ) {\n\t\tj = M - N + i;\n\t\tif ( j < 0 ) {\n\t\t\t// Prepended singleton dimension; stride is zero...\n\t\t\tcontinue;\n\t\t}\n\t\td = sh[ j ];\n\t\tdim = shape[ i ];\n\t\tif ( dim !== 0 && dim < d ) {\n\t\t\tthrow new Error( format( '0Lx5T', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t\tif ( d === dim ) {\n\t\t\tstrides[ i ] = st[ j ];\n\t\t} else if ( d === 1 ) {\n\t\t\t// In order to broadcast dimensions, we set the stride for that dimension to zero...\n\t\t\tstrides[ i ] = 0;\n\t\t} else {\n\t\t\t// At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when \"tiling\" an array; e.g., `dim=4` and `d=2`)...\n\t\t\tthrow new Error( format( '0Lx5U', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t}\n\treturn ndarray( arr.dtype, arr.data, copy( shape ), strides, arr.offset, arr.order ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nexport default broadcastArray;\n"],"names":["copyArray","arr","out","i","length","push","broadcastArray","shape","strides","dim","sh","st","N","M","d","j","Error","format","copy","join","ndarray","dtype","data","offset","order"],"mappings":";;sLAsCA,SAASA,EAAWC,GACnB,IAAIC,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAIF,EAAIG,OAAQD,IAC5BD,EAAIG,KAAMJ,EAAKE,IAEhB,OAAOD,CACR,CCsCA,SAASI,EAAgBL,EAAKM,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAX,EACAY,EAKJ,IAHAH,EAAIL,EAAMH,SAEVS,GADAH,EAAKT,EAAIM,OACFH,QAEN,MAAM,IAAIY,MAAOC,EAAQ,UAI1B,IADAT,EAAU,GACJL,EAAI,EAAGA,EAAIS,EAAGT,IACnBK,EAAQH,KAAM,GAIf,IADAM,EAAKV,EAAIO,QACHL,EAAIS,EAAE,EAAGT,GAAK,EAAGA,IAEtB,MADAY,EAAIF,EAAID,EAAIT,GACH,GAAT,CAMA,GAFAW,EAAIJ,EAAIK,GAEK,KADbN,EAAMF,EAAOJ,KACKM,EAAMK,EACvB,MAAM,IAAIE,MAAOC,EAAQ,QAASC,EAAMR,GAAKS,KAAM,MAAQD,EAAMX,GAAQY,KAAM,MAAQhB,IAExF,GAAKW,IAAML,EACVD,EAASL,GAAMQ,EAAII,OACb,IAAW,IAAND,EAKX,MAAM,IAAIE,MAAOC,EAAQ,QAASC,EAAMR,GAAKS,KAAM,MAAQD,EAAMX,GAAQY,KAAM,MAAQhB,IAHvFK,EAASL,GAAM,CAIf,CAdA,CAgBF,OAAOiB,EAASnB,EAAIoB,MAAOpB,EAAIqB,KAAMJ,EAAMX,GAASC,EAASP,EAAIsB,OAAQtB,EAAIuB,MAC9E"} \ No newline at end of file diff --git a/lib/copy_array.js b/lib/copy_array.js deleted file mode 100644 index 6c9a427..0000000 --- a/lib/copy_array.js +++ /dev/null @@ -1,53 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN / - -/** -* Copies an array-like object to an array. -* -* @private -* @param {ArrayLikeObject} arr - input array -* @returns {Array} output array -* -* @example -* var arr = [ 1, 2, 3 ]; -* -* var out = copyArray( arr ); -* // returns [ 1, 2, 3 ] -* -* var bool = ( out === arr ); -* // returns false -*/ -function copyArray( arr ) { - var out; - var i; - - out = []; - for ( i = 0; i < arr.length; i++ ) { - out.push( arr[ i ] ); - } - return out; -} - - -// EXPORTS // - -module.exports = copyArray; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index b6aaa86..0000000 --- a/lib/index.js +++ /dev/null @@ -1,68 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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. -* -* @module @stdlib/ndarray-base-broadcast-array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var broadcastArray = require( '@stdlib/ndarray-base-broadcast-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = broadcastArray( 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 8aa2804..0000000 --- a/lib/main.js +++ /dev/null @@ -1,137 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var copy = require( './copy_array.js' ); - - -// MAIN // - -/** -* Broadcasts an ndarray to a specified shape. -* -* ## Notes -* -* - The 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. -* -* @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 = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] ); -* // throws -*/ -function broadcastArray( arr, shape ) { - var strides; - var dim; - var sh; - var st; - var N; - var M; - var d; - var i; - var j; - - N = shape.length; - sh = arr.shape; - M = sh.length; - if ( N < M ) { - throw new Error( format( '0Lx0Z' ) ); - } - // Initialize a strides array... - strides = []; - for ( i = 0; i < N; i++ ) { - strides.push( 0 ); - } - // Determine the output array strides... - st = arr.strides; - for ( i = N-1; i >= 0; i-- ) { - j = M - N + i; - if ( j < 0 ) { - // Prepended singleton dimension; stride is zero... - continue; - } - d = sh[ j ]; - dim = shape[ i ]; - if ( dim !== 0 && dim < d ) { - throw new Error( format( '0Lx5T', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); - } - if ( d === dim ) { - strides[ i ] = st[ j ]; - } else if ( d === 1 ) { - // In order to broadcast dimensions, we set the stride for that dimension to zero... - strides[ i ] = 0; - } else { - // At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when "tiling" an array; e.g., `dim=4` and `d=2`)... - throw new Error( format( '0Lx5U', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); - } - } - return ndarray( arr.dtype, arr.data, copy( shape ), strides, arr.offset, arr.order ); // eslint-disable-line max-len -} - - -// EXPORTS // - -module.exports = broadcastArray; diff --git a/package.json b/package.json index 2c99fad..2be9a19 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.6", "description": "Broadcast an ndarray to a specified 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,38 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-base-ctor": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^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-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", @@ -84,7 +29,6 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..fbd6223 --- /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 97decdb..0000000 --- a/test/test.js +++ /dev/null @@ -1,511 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 broadcastArray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastArray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a desired shape which has fewer dimensions than 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() { - broadcastArray( 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() { - broadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape and an input array shape 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() { - broadcastArray( x, value ); - }; - } -}); - -tape( 'the function returns a "base" ndarray instance', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = broadcastArray( 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 = broadcastArray( 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.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, 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 = broadcastArray( x, expected ); - - actual = y.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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 2d4964069fc6225e8b579d6e290baf726007c3a2 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 4 Nov 2022 00:31:55 +0000 Subject: [PATCH 23/91] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index fca038e..8aa2804 100644 --- a/lib/main.js +++ b/lib/main.js @@ -21,7 +21,7 @@ // MODULES // var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var copy = require( './copy_array.js' ); @@ -98,7 +98,7 @@ function broadcastArray( arr, shape ) { sh = arr.shape; M = sh.length; if ( N < M ) { - throw new Error( 'invalid argument. Cannot broadcast an array to a shape having fewer dimensions. Arrays can only be broadcasted to shapes having the same or more dimensions.' ); + throw new Error( format( '0Lx0Z' ) ); } // Initialize a strides array... strides = []; @@ -116,7 +116,7 @@ function broadcastArray( arr, shape ) { d = sh[ j ]; dim = shape[ i ]; if ( dim !== 0 && dim < d ) { - throw new Error( format( 'invalid argument. Input array cannot be broadcast to the specified shape, as the specified shape has a dimension whose size is less than the size of the corresponding dimension in the input array. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); + throw new Error( format( '0Lx5T', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); } if ( d === dim ) { strides[ i ] = st[ j ]; @@ -125,7 +125,7 @@ function broadcastArray( arr, shape ) { strides[ i ] = 0; } else { // At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when "tiling" an array; e.g., `dim=4` and `d=2`)... - throw new Error( format( 'invalid argument. Input array and the specified shape are broadcast incompatible. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); + throw new Error( format( '0Lx5U', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); } } return ndarray( arr.dtype, arr.data, copy( shape ), strides, arr.offset, arr.order ); // eslint-disable-line max-len diff --git a/package.json b/package.json index 96b6613..2c99fad 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ }, "dependencies": { "@stdlib/ndarray-base-ctor": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x" }, "devDependencies": { From 974131618b64df0345d26ec8700c1c2fd994b107 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 4 Nov 2022 11:24:04 +0000 Subject: [PATCH 24/91] Remove files --- index.d.ts | 80 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4044 ------------------------------------------------- 4 files changed, 4129 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 a0d0239..0000000 --- a/index.d.ts +++ /dev/null @@ -1,80 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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. -* -* ## Notes -* -* - The function throws an error if a provided ndarray is incompatible with a provided shape. -* - The 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. -* - The returned array is a "base" ndarray, and, thus, the returned array 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 always returns a new ndarray instance even if the input ndarray shape and the desired shape are the same. -* -* @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 -* @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 = broadcastArray( 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 broadcastArray( arr: ndarray, shape: ArrayLike ): ndarray; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = broadcastArray; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 02a38d0..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-ctor@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function e(r){var t,e;for(t=[],e=0;e=0;l--)if(!((m=a-h+l)<0)){if(j=f[m],0!==(i=n[l])&&i\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction broadcastArray( arr, shape ) {\n\tvar strides;\n\tvar dim;\n\tvar sh;\n\tvar st;\n\tvar N;\n\tvar M;\n\tvar d;\n\tvar i;\n\tvar j;\n\n\tN = shape.length;\n\tsh = arr.shape;\n\tM = sh.length;\n\tif ( N < M ) {\n\t\tthrow new Error( format( '0Lx0Z' ) );\n\t}\n\t// Initialize a strides array...\n\tstrides = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tstrides.push( 0 );\n\t}\n\t// Determine the output array strides...\n\tst = arr.strides;\n\tfor ( i = N-1; i >= 0; i-- ) {\n\t\tj = M - N + i;\n\t\tif ( j < 0 ) {\n\t\t\t// Prepended singleton dimension; stride is zero...\n\t\t\tcontinue;\n\t\t}\n\t\td = sh[ j ];\n\t\tdim = shape[ i ];\n\t\tif ( dim !== 0 && dim < d ) {\n\t\t\tthrow new Error( format( '0Lx5T', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t\tif ( d === dim ) {\n\t\t\tstrides[ i ] = st[ j ];\n\t\t} else if ( d === 1 ) {\n\t\t\t// In order to broadcast dimensions, we set the stride for that dimension to zero...\n\t\t\tstrides[ i ] = 0;\n\t\t} else {\n\t\t\t// At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when \"tiling\" an array; e.g., `dim=4` and `d=2`)...\n\t\t\tthrow new Error( format( '0Lx5U', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t}\n\treturn ndarray( arr.dtype, arr.data, copy( shape ), strides, arr.offset, arr.order ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nexport default broadcastArray;\n"],"names":["copyArray","arr","out","i","length","push","broadcastArray","shape","strides","dim","sh","st","N","M","d","j","Error","format","copy","join","ndarray","dtype","data","offset","order"],"mappings":";;sLAsCA,SAASA,EAAWC,GACnB,IAAIC,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAIF,EAAIG,OAAQD,IAC5BD,EAAIG,KAAMJ,EAAKE,IAEhB,OAAOD,CACR,CCsCA,SAASI,EAAgBL,EAAKM,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAX,EACAY,EAKJ,IAHAH,EAAIL,EAAMH,SAEVS,GADAH,EAAKT,EAAIM,OACFH,QAEN,MAAM,IAAIY,MAAOC,EAAQ,UAI1B,IADAT,EAAU,GACJL,EAAI,EAAGA,EAAIS,EAAGT,IACnBK,EAAQH,KAAM,GAIf,IADAM,EAAKV,EAAIO,QACHL,EAAIS,EAAE,EAAGT,GAAK,EAAGA,IAEtB,MADAY,EAAIF,EAAID,EAAIT,GACH,GAAT,CAMA,GAFAW,EAAIJ,EAAIK,GAEK,KADbN,EAAMF,EAAOJ,KACKM,EAAMK,EACvB,MAAM,IAAIE,MAAOC,EAAQ,QAASC,EAAMR,GAAKS,KAAM,MAAQD,EAAMX,GAAQY,KAAM,MAAQhB,IAExF,GAAKW,IAAML,EACVD,EAASL,GAAMQ,EAAII,OACb,IAAW,IAAND,EAKX,MAAM,IAAIE,MAAOC,EAAQ,QAASC,EAAMR,GAAKS,KAAM,MAAQD,EAAMX,GAAQY,KAAM,MAAQhB,IAHvFK,EAASL,GAAM,CAIf,CAdA,CAgBF,OAAOiB,EAASnB,EAAIoB,MAAOpB,EAAIqB,KAAMJ,EAAMX,GAASC,EAASP,EAAIsB,OAAQtB,EAAIuB,MAC9E"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index fbd6223..0000000 --- a/stats.html +++ /dev/null @@ -1,4044 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 19036983f122095627f2562fbed67fd2d71127dc Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 4 Nov 2022 11:24:56 +0000 Subject: [PATCH 25/91] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 781 ---- .github/workflows/publish.yml | 117 - .github/workflows/test.yml | 92 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 178 - .npmignore | 227 -- .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 47 +- benchmark/benchmark.js | 161 - benchmark/benchmark.ndims.js | 110 - branches.md | 53 - docs/repl.txt | 65 - docs/types/test.ts | 94 - examples/index.js | 49 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/copy_array.js | 53 - lib/index.js | 68 - lib/main.js | 137 - package.json | 60 +- stats.html | 4044 +++++++++++++++++++++ test/test.js | 511 --- 39 files changed, 4072 insertions(+), 4312 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 (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/copy_array.js 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 508fbfd..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-11-03T22:41:22.546Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 6c59584..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-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 9a95c7d..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-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 16cec43..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: '28 4 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 37ddb4f..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,781 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -164,7 +157,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]. @@ -224,11 +217,11 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-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 7983cf3..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,161 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 broadcastArray = 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 = broadcastArray( 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', 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 = broadcastArray( 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', 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 = broadcastArray( 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(); -}); diff --git a/benchmark/benchmark.ndims.js b/benchmark/benchmark.ndims.js deleted file mode 100644 index 141a816..0000000 --- a/benchmark/benchmark.ndims.js +++ /dev/null @@ -1,110 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 broadcastArray = 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 = broadcastArray( 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 1aef646..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-array" -click B href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/main" -click C href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/production" -click D href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-array -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-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 db0f44c..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,65 +0,0 @@ - -{{alias}}( arr, shape ) - Broadcasts an ndarray to a specified shape. - - The 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. - - The returned array is a "base" ndarray, and, thus, the returned array 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. - - The function always returns a new ndarray instance even if the input ndarray - shape and the desired shape are the same. - - 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 4041dc7..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,94 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 broadcastArray = 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(); - - broadcastArray( x, [ 2, 2, 2 ] ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is not provided a first argument which is an ndarray... -{ - broadcastArray( '5', [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( 5, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( true, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( false, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( null, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( {}, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( [ '5' ], [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( ( 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(); - - broadcastArray( x, '5' ); // $ExpectError - broadcastArray( x, 5 ); // $ExpectError - broadcastArray( x, true ); // $ExpectError - broadcastArray( x, false ); // $ExpectError - broadcastArray( x, null ); // $ExpectError - broadcastArray( x, {} ); // $ExpectError - broadcastArray( x, [ '5' ] ); // $ExpectError - broadcastArray( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - - broadcastArray(); // $ExpectError - broadcastArray( x ); // $ExpectError - broadcastArray( x, [ 1, 2, 3 ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index f0dc7b6..0000000 --- a/examples/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 broadcastArray = require( './../lib' ); - -// Create a 2x2 array: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -// returns - -// Broadcast the array to 3x2x2: -var y = broadcastArray( 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 sub; -var v; -var i; -for ( i = 0; i < N; i++ ) { - v = y.iget( i ); - sub = ind2sub( sh, i ); - console.log( 'Y[%s] = %d', sub.join( ', ' ), v ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index f8117ef..a0d0239 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..02a38d0 --- /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-ctor@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function e(r){var t,e;for(t=[],e=0;e=0;l--)if(!((m=a-h+l)<0)){if(j=f[m],0!==(i=n[l])&&i\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction broadcastArray( arr, shape ) {\n\tvar strides;\n\tvar dim;\n\tvar sh;\n\tvar st;\n\tvar N;\n\tvar M;\n\tvar d;\n\tvar i;\n\tvar j;\n\n\tN = shape.length;\n\tsh = arr.shape;\n\tM = sh.length;\n\tif ( N < M ) {\n\t\tthrow new Error( format( '0Lx0Z' ) );\n\t}\n\t// Initialize a strides array...\n\tstrides = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tstrides.push( 0 );\n\t}\n\t// Determine the output array strides...\n\tst = arr.strides;\n\tfor ( i = N-1; i >= 0; i-- ) {\n\t\tj = M - N + i;\n\t\tif ( j < 0 ) {\n\t\t\t// Prepended singleton dimension; stride is zero...\n\t\t\tcontinue;\n\t\t}\n\t\td = sh[ j ];\n\t\tdim = shape[ i ];\n\t\tif ( dim !== 0 && dim < d ) {\n\t\t\tthrow new Error( format( '0Lx5T', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t\tif ( d === dim ) {\n\t\t\tstrides[ i ] = st[ j ];\n\t\t} else if ( d === 1 ) {\n\t\t\t// In order to broadcast dimensions, we set the stride for that dimension to zero...\n\t\t\tstrides[ i ] = 0;\n\t\t} else {\n\t\t\t// At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when \"tiling\" an array; e.g., `dim=4` and `d=2`)...\n\t\t\tthrow new Error( format( '0Lx5U', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t}\n\treturn ndarray( arr.dtype, arr.data, copy( shape ), strides, arr.offset, arr.order ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nexport default broadcastArray;\n"],"names":["copyArray","arr","out","i","length","push","broadcastArray","shape","strides","dim","sh","st","N","M","d","j","Error","format","copy","join","ndarray","dtype","data","offset","order"],"mappings":";;sLAsCA,SAASA,EAAWC,GACnB,IAAIC,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAIF,EAAIG,OAAQD,IAC5BD,EAAIG,KAAMJ,EAAKE,IAEhB,OAAOD,CACR,CCsCA,SAASI,EAAgBL,EAAKM,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAX,EACAY,EAKJ,IAHAH,EAAIL,EAAMH,SAEVS,GADAH,EAAKT,EAAIM,OACFH,QAEN,MAAM,IAAIY,MAAOC,EAAQ,UAI1B,IADAT,EAAU,GACJL,EAAI,EAAGA,EAAIS,EAAGT,IACnBK,EAAQH,KAAM,GAIf,IADAM,EAAKV,EAAIO,QACHL,EAAIS,EAAE,EAAGT,GAAK,EAAGA,IAEtB,MADAY,EAAIF,EAAID,EAAIT,GACH,GAAT,CAMA,GAFAW,EAAIJ,EAAIK,GAEK,KADbN,EAAMF,EAAOJ,KACKM,EAAMK,EACvB,MAAM,IAAIE,MAAOC,EAAQ,QAASC,EAAMR,GAAKS,KAAM,MAAQD,EAAMX,GAAQY,KAAM,MAAQhB,IAExF,GAAKW,IAAML,EACVD,EAASL,GAAMQ,EAAII,OACb,IAAW,IAAND,EAKX,MAAM,IAAIE,MAAOC,EAAQ,QAASC,EAAMR,GAAKS,KAAM,MAAQD,EAAMX,GAAQY,KAAM,MAAQhB,IAHvFK,EAASL,GAAM,CAIf,CAdA,CAgBF,OAAOiB,EAASnB,EAAIoB,MAAOpB,EAAIqB,KAAMJ,EAAMX,GAASC,EAASP,EAAIsB,OAAQtB,EAAIuB,MAC9E"} \ No newline at end of file diff --git a/lib/copy_array.js b/lib/copy_array.js deleted file mode 100644 index 6c9a427..0000000 --- a/lib/copy_array.js +++ /dev/null @@ -1,53 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN / - -/** -* Copies an array-like object to an array. -* -* @private -* @param {ArrayLikeObject} arr - input array -* @returns {Array} output array -* -* @example -* var arr = [ 1, 2, 3 ]; -* -* var out = copyArray( arr ); -* // returns [ 1, 2, 3 ] -* -* var bool = ( out === arr ); -* // returns false -*/ -function copyArray( arr ) { - var out; - var i; - - out = []; - for ( i = 0; i < arr.length; i++ ) { - out.push( arr[ i ] ); - } - return out; -} - - -// EXPORTS // - -module.exports = copyArray; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index b6aaa86..0000000 --- a/lib/index.js +++ /dev/null @@ -1,68 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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. -* -* @module @stdlib/ndarray-base-broadcast-array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var broadcastArray = require( '@stdlib/ndarray-base-broadcast-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = broadcastArray( 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 8aa2804..0000000 --- a/lib/main.js +++ /dev/null @@ -1,137 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var copy = require( './copy_array.js' ); - - -// MAIN // - -/** -* Broadcasts an ndarray to a specified shape. -* -* ## Notes -* -* - The 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. -* -* @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 = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] ); -* // throws -*/ -function broadcastArray( arr, shape ) { - var strides; - var dim; - var sh; - var st; - var N; - var M; - var d; - var i; - var j; - - N = shape.length; - sh = arr.shape; - M = sh.length; - if ( N < M ) { - throw new Error( format( '0Lx0Z' ) ); - } - // Initialize a strides array... - strides = []; - for ( i = 0; i < N; i++ ) { - strides.push( 0 ); - } - // Determine the output array strides... - st = arr.strides; - for ( i = N-1; i >= 0; i-- ) { - j = M - N + i; - if ( j < 0 ) { - // Prepended singleton dimension; stride is zero... - continue; - } - d = sh[ j ]; - dim = shape[ i ]; - if ( dim !== 0 && dim < d ) { - throw new Error( format( '0Lx5T', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); - } - if ( d === dim ) { - strides[ i ] = st[ j ]; - } else if ( d === 1 ) { - // In order to broadcast dimensions, we set the stride for that dimension to zero... - strides[ i ] = 0; - } else { - // At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when "tiling" an array; e.g., `dim=4` and `d=2`)... - throw new Error( format( '0Lx5U', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); - } - } - return ndarray( arr.dtype, arr.data, copy( shape ), strides, arr.offset, arr.order ); // eslint-disable-line max-len -} - - -// EXPORTS // - -module.exports = broadcastArray; diff --git a/package.json b/package.json index 2c99fad..2be9a19 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.6", "description": "Broadcast an ndarray to a specified 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,38 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-base-ctor": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^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-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", @@ -84,7 +29,6 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..1225246 --- /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 97decdb..0000000 --- a/test/test.js +++ /dev/null @@ -1,511 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 broadcastArray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastArray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a desired shape which has fewer dimensions than 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() { - broadcastArray( 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() { - broadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape and an input array shape 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() { - broadcastArray( x, value ); - }; - } -}); - -tape( 'the function returns a "base" ndarray instance', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = broadcastArray( 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 = broadcastArray( 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.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, 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 = broadcastArray( x, expected ); - - actual = y.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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 bb98dd567b2d8f2063a9f26a125316843d610a82 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Dec 2022 04:28:57 +0000 Subject: [PATCH 26/91] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index fca038e..8aa2804 100644 --- a/lib/main.js +++ b/lib/main.js @@ -21,7 +21,7 @@ // MODULES // var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var copy = require( './copy_array.js' ); @@ -98,7 +98,7 @@ function broadcastArray( arr, shape ) { sh = arr.shape; M = sh.length; if ( N < M ) { - throw new Error( 'invalid argument. Cannot broadcast an array to a shape having fewer dimensions. Arrays can only be broadcasted to shapes having the same or more dimensions.' ); + throw new Error( format( '0Lx0Z' ) ); } // Initialize a strides array... strides = []; @@ -116,7 +116,7 @@ function broadcastArray( arr, shape ) { d = sh[ j ]; dim = shape[ i ]; if ( dim !== 0 && dim < d ) { - throw new Error( format( 'invalid argument. Input array cannot be broadcast to the specified shape, as the specified shape has a dimension whose size is less than the size of the corresponding dimension in the input array. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); + throw new Error( format( '0Lx5T', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); } if ( d === dim ) { strides[ i ] = st[ j ]; @@ -125,7 +125,7 @@ function broadcastArray( arr, shape ) { strides[ i ] = 0; } else { // At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when "tiling" an array; e.g., `dim=4` and `d=2`)... - throw new Error( format( 'invalid argument. Input array and the specified shape are broadcast incompatible. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); + throw new Error( format( '0Lx5U', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); } } return ndarray( arr.dtype, arr.data, copy( shape ), strides, arr.offset, arr.order ); // eslint-disable-line max-len diff --git a/package.json b/package.json index acd4e5f..145ab56 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ }, "dependencies": { "@stdlib/ndarray-base-ctor": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x" }, "devDependencies": { From 06f0a765a12ef0be697611e2cfb60ce49d299340 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Dec 2022 12:21:37 +0000 Subject: [PATCH 27/91] Remove files --- index.d.ts | 80 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4044 ------------------------------------------------- 4 files changed, 4129 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 a0d0239..0000000 --- a/index.d.ts +++ /dev/null @@ -1,80 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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. -* -* ## Notes -* -* - The function throws an error if a provided ndarray is incompatible with a provided shape. -* - The 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. -* - The returned array is a "base" ndarray, and, thus, the returned array 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 always returns a new ndarray instance even if the input ndarray shape and the desired shape are the same. -* -* @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 -* @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 = broadcastArray( 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 broadcastArray( arr: ndarray, shape: ArrayLike ): ndarray; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = broadcastArray; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 02a38d0..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-ctor@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function e(r){var t,e;for(t=[],e=0;e=0;l--)if(!((m=a-h+l)<0)){if(j=f[m],0!==(i=n[l])&&i\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction broadcastArray( arr, shape ) {\n\tvar strides;\n\tvar dim;\n\tvar sh;\n\tvar st;\n\tvar N;\n\tvar M;\n\tvar d;\n\tvar i;\n\tvar j;\n\n\tN = shape.length;\n\tsh = arr.shape;\n\tM = sh.length;\n\tif ( N < M ) {\n\t\tthrow new Error( format( '0Lx0Z' ) );\n\t}\n\t// Initialize a strides array...\n\tstrides = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tstrides.push( 0 );\n\t}\n\t// Determine the output array strides...\n\tst = arr.strides;\n\tfor ( i = N-1; i >= 0; i-- ) {\n\t\tj = M - N + i;\n\t\tif ( j < 0 ) {\n\t\t\t// Prepended singleton dimension; stride is zero...\n\t\t\tcontinue;\n\t\t}\n\t\td = sh[ j ];\n\t\tdim = shape[ i ];\n\t\tif ( dim !== 0 && dim < d ) {\n\t\t\tthrow new Error( format( '0Lx5T', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t\tif ( d === dim ) {\n\t\t\tstrides[ i ] = st[ j ];\n\t\t} else if ( d === 1 ) {\n\t\t\t// In order to broadcast dimensions, we set the stride for that dimension to zero...\n\t\t\tstrides[ i ] = 0;\n\t\t} else {\n\t\t\t// At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when \"tiling\" an array; e.g., `dim=4` and `d=2`)...\n\t\t\tthrow new Error( format( '0Lx5U', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t}\n\treturn ndarray( arr.dtype, arr.data, copy( shape ), strides, arr.offset, arr.order ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nexport default broadcastArray;\n"],"names":["copyArray","arr","out","i","length","push","broadcastArray","shape","strides","dim","sh","st","N","M","d","j","Error","format","copy","join","ndarray","dtype","data","offset","order"],"mappings":";;sLAsCA,SAASA,EAAWC,GACnB,IAAIC,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAIF,EAAIG,OAAQD,IAC5BD,EAAIG,KAAMJ,EAAKE,IAEhB,OAAOD,CACR,CCsCA,SAASI,EAAgBL,EAAKM,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAX,EACAY,EAKJ,IAHAH,EAAIL,EAAMH,SAEVS,GADAH,EAAKT,EAAIM,OACFH,QAEN,MAAM,IAAIY,MAAOC,EAAQ,UAI1B,IADAT,EAAU,GACJL,EAAI,EAAGA,EAAIS,EAAGT,IACnBK,EAAQH,KAAM,GAIf,IADAM,EAAKV,EAAIO,QACHL,EAAIS,EAAE,EAAGT,GAAK,EAAGA,IAEtB,MADAY,EAAIF,EAAID,EAAIT,GACH,GAAT,CAMA,GAFAW,EAAIJ,EAAIK,GAEK,KADbN,EAAMF,EAAOJ,KACKM,EAAMK,EACvB,MAAM,IAAIE,MAAOC,EAAQ,QAASC,EAAMR,GAAKS,KAAM,MAAQD,EAAMX,GAAQY,KAAM,MAAQhB,IAExF,GAAKW,IAAML,EACVD,EAASL,GAAMQ,EAAII,OACb,IAAW,IAAND,EAKX,MAAM,IAAIE,MAAOC,EAAQ,QAASC,EAAMR,GAAKS,KAAM,MAAQD,EAAMX,GAAQY,KAAM,MAAQhB,IAHvFK,EAASL,GAAM,CAIf,CAdA,CAgBF,OAAOiB,EAASnB,EAAIoB,MAAOpB,EAAIqB,KAAMJ,EAAMX,GAASC,EAASP,EAAIsB,OAAQtB,EAAIuB,MAC9E"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 1225246..0000000 --- a/stats.html +++ /dev/null @@ -1,4044 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 4e87a300886f17d78cd17ad980e4d00a2e8ab594 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Dec 2022 12:22:29 +0000 Subject: [PATCH 28/91] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 781 ---- .github/workflows/publish.yml | 117 - .github/workflows/test.yml | 92 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 183 - .npmignore | 227 -- .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 47 +- benchmark/benchmark.js | 161 - benchmark/benchmark.ndims.js | 110 - branches.md | 53 - docs/repl.txt | 65 - docs/types/test.ts | 94 - examples/index.js | 49 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/copy_array.js | 53 - lib/index.js | 68 - lib/main.js | 137 - package.json | 60 +- stats.html | 4044 +++++++++++++++++++++ test/test.js | 511 --- 39 files changed, 4072 insertions(+), 4317 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 (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/copy_array.js 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 c2db0a0..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-12-01T02:30:39.030Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 6c59584..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-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 9a95c7d..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-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 16cec43..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: '28 4 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 37ddb4f..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,781 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -164,7 +157,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]. @@ -224,11 +217,11 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-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 7983cf3..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,161 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 broadcastArray = 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 = broadcastArray( 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', 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 = broadcastArray( 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', 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 = broadcastArray( 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(); -}); diff --git a/benchmark/benchmark.ndims.js b/benchmark/benchmark.ndims.js deleted file mode 100644 index 141a816..0000000 --- a/benchmark/benchmark.ndims.js +++ /dev/null @@ -1,110 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 broadcastArray = 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 = broadcastArray( 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 1aef646..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-array" -click B href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/main" -click C href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/production" -click D href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-array -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-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 db0f44c..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,65 +0,0 @@ - -{{alias}}( arr, shape ) - Broadcasts an ndarray to a specified shape. - - The 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. - - The returned array is a "base" ndarray, and, thus, the returned array 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. - - The function always returns a new ndarray instance even if the input ndarray - shape and the desired shape are the same. - - 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 4041dc7..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,94 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 broadcastArray = 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(); - - broadcastArray( x, [ 2, 2, 2 ] ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is not provided a first argument which is an ndarray... -{ - broadcastArray( '5', [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( 5, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( true, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( false, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( null, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( {}, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( [ '5' ], [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( ( 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(); - - broadcastArray( x, '5' ); // $ExpectError - broadcastArray( x, 5 ); // $ExpectError - broadcastArray( x, true ); // $ExpectError - broadcastArray( x, false ); // $ExpectError - broadcastArray( x, null ); // $ExpectError - broadcastArray( x, {} ); // $ExpectError - broadcastArray( x, [ '5' ] ); // $ExpectError - broadcastArray( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - - broadcastArray(); // $ExpectError - broadcastArray( x ); // $ExpectError - broadcastArray( x, [ 1, 2, 3 ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index f0dc7b6..0000000 --- a/examples/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 broadcastArray = require( './../lib' ); - -// Create a 2x2 array: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -// returns - -// Broadcast the array to 3x2x2: -var y = broadcastArray( 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 sub; -var v; -var i; -for ( i = 0; i < N; i++ ) { - v = y.iget( i ); - sub = ind2sub( sh, i ); - console.log( 'Y[%s] = %d', sub.join( ', ' ), v ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index f8117ef..a0d0239 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..02a38d0 --- /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-ctor@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function e(r){var t,e;for(t=[],e=0;e=0;l--)if(!((m=a-h+l)<0)){if(j=f[m],0!==(i=n[l])&&i\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction broadcastArray( arr, shape ) {\n\tvar strides;\n\tvar dim;\n\tvar sh;\n\tvar st;\n\tvar N;\n\tvar M;\n\tvar d;\n\tvar i;\n\tvar j;\n\n\tN = shape.length;\n\tsh = arr.shape;\n\tM = sh.length;\n\tif ( N < M ) {\n\t\tthrow new Error( format( '0Lx0Z' ) );\n\t}\n\t// Initialize a strides array...\n\tstrides = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tstrides.push( 0 );\n\t}\n\t// Determine the output array strides...\n\tst = arr.strides;\n\tfor ( i = N-1; i >= 0; i-- ) {\n\t\tj = M - N + i;\n\t\tif ( j < 0 ) {\n\t\t\t// Prepended singleton dimension; stride is zero...\n\t\t\tcontinue;\n\t\t}\n\t\td = sh[ j ];\n\t\tdim = shape[ i ];\n\t\tif ( dim !== 0 && dim < d ) {\n\t\t\tthrow new Error( format( '0Lx5T', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t\tif ( d === dim ) {\n\t\t\tstrides[ i ] = st[ j ];\n\t\t} else if ( d === 1 ) {\n\t\t\t// In order to broadcast dimensions, we set the stride for that dimension to zero...\n\t\t\tstrides[ i ] = 0;\n\t\t} else {\n\t\t\t// At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when \"tiling\" an array; e.g., `dim=4` and `d=2`)...\n\t\t\tthrow new Error( format( '0Lx5U', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t}\n\treturn ndarray( arr.dtype, arr.data, copy( shape ), strides, arr.offset, arr.order ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nexport default broadcastArray;\n"],"names":["copyArray","arr","out","i","length","push","broadcastArray","shape","strides","dim","sh","st","N","M","d","j","Error","format","copy","join","ndarray","dtype","data","offset","order"],"mappings":";;sLAsCA,SAASA,EAAWC,GACnB,IAAIC,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAIF,EAAIG,OAAQD,IAC5BD,EAAIG,KAAMJ,EAAKE,IAEhB,OAAOD,CACR,CCsCA,SAASI,EAAgBL,EAAKM,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAX,EACAY,EAKJ,IAHAH,EAAIL,EAAMH,SAEVS,GADAH,EAAKT,EAAIM,OACFH,QAEN,MAAM,IAAIY,MAAOC,EAAQ,UAI1B,IADAT,EAAU,GACJL,EAAI,EAAGA,EAAIS,EAAGT,IACnBK,EAAQH,KAAM,GAIf,IADAM,EAAKV,EAAIO,QACHL,EAAIS,EAAE,EAAGT,GAAK,EAAGA,IAEtB,MADAY,EAAIF,EAAID,EAAIT,GACH,GAAT,CAMA,GAFAW,EAAIJ,EAAIK,GAEK,KADbN,EAAMF,EAAOJ,KACKM,EAAMK,EACvB,MAAM,IAAIE,MAAOC,EAAQ,QAASC,EAAMR,GAAKS,KAAM,MAAQD,EAAMX,GAAQY,KAAM,MAAQhB,IAExF,GAAKW,IAAML,EACVD,EAASL,GAAMQ,EAAII,OACb,IAAW,IAAND,EAKX,MAAM,IAAIE,MAAOC,EAAQ,QAASC,EAAMR,GAAKS,KAAM,MAAQD,EAAMX,GAAQY,KAAM,MAAQhB,IAHvFK,EAASL,GAAM,CAIf,CAdA,CAgBF,OAAOiB,EAASnB,EAAIoB,MAAOpB,EAAIqB,KAAMJ,EAAMX,GAASC,EAASP,EAAIsB,OAAQtB,EAAIuB,MAC9E"} \ No newline at end of file diff --git a/lib/copy_array.js b/lib/copy_array.js deleted file mode 100644 index 6c9a427..0000000 --- a/lib/copy_array.js +++ /dev/null @@ -1,53 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN / - -/** -* Copies an array-like object to an array. -* -* @private -* @param {ArrayLikeObject} arr - input array -* @returns {Array} output array -* -* @example -* var arr = [ 1, 2, 3 ]; -* -* var out = copyArray( arr ); -* // returns [ 1, 2, 3 ] -* -* var bool = ( out === arr ); -* // returns false -*/ -function copyArray( arr ) { - var out; - var i; - - out = []; - for ( i = 0; i < arr.length; i++ ) { - out.push( arr[ i ] ); - } - return out; -} - - -// EXPORTS // - -module.exports = copyArray; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index b6aaa86..0000000 --- a/lib/index.js +++ /dev/null @@ -1,68 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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. -* -* @module @stdlib/ndarray-base-broadcast-array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var broadcastArray = require( '@stdlib/ndarray-base-broadcast-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = broadcastArray( 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 8aa2804..0000000 --- a/lib/main.js +++ /dev/null @@ -1,137 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var copy = require( './copy_array.js' ); - - -// MAIN // - -/** -* Broadcasts an ndarray to a specified shape. -* -* ## Notes -* -* - The 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. -* -* @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 = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] ); -* // throws -*/ -function broadcastArray( arr, shape ) { - var strides; - var dim; - var sh; - var st; - var N; - var M; - var d; - var i; - var j; - - N = shape.length; - sh = arr.shape; - M = sh.length; - if ( N < M ) { - throw new Error( format( '0Lx0Z' ) ); - } - // Initialize a strides array... - strides = []; - for ( i = 0; i < N; i++ ) { - strides.push( 0 ); - } - // Determine the output array strides... - st = arr.strides; - for ( i = N-1; i >= 0; i-- ) { - j = M - N + i; - if ( j < 0 ) { - // Prepended singleton dimension; stride is zero... - continue; - } - d = sh[ j ]; - dim = shape[ i ]; - if ( dim !== 0 && dim < d ) { - throw new Error( format( '0Lx5T', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); - } - if ( d === dim ) { - strides[ i ] = st[ j ]; - } else if ( d === 1 ) { - // In order to broadcast dimensions, we set the stride for that dimension to zero... - strides[ i ] = 0; - } else { - // At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when "tiling" an array; e.g., `dim=4` and `d=2`)... - throw new Error( format( '0Lx5U', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); - } - } - return ndarray( arr.dtype, arr.data, copy( shape ), strides, arr.offset, arr.order ); // eslint-disable-line max-len -} - - -// EXPORTS // - -module.exports = broadcastArray; diff --git a/package.json b/package.json index 145ab56..2be9a19 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.6", "description": "Broadcast an ndarray to a specified 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,38 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-base-ctor": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^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-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", @@ -84,7 +29,6 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..9dc9c3b --- /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 97decdb..0000000 --- a/test/test.js +++ /dev/null @@ -1,511 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 broadcastArray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastArray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a desired shape which has fewer dimensions than 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() { - broadcastArray( 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() { - broadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape and an input array shape 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() { - broadcastArray( x, value ); - }; - } -}); - -tape( 'the function returns a "base" ndarray instance', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = broadcastArray( 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 = broadcastArray( 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.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, 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 = broadcastArray( x, expected ); - - actual = y.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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 c42cf7eb56234bfd1c8be0c1a213b873af28d49e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 8 Oct 2023 11:14:33 +0000 Subject: [PATCH 29/91] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b6b035d..fee8cb9 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "@stdlib/ndarray-base-order": "github:stdlib-js/ndarray-base-order#main", "@stdlib/ndarray-base-shape": "github:stdlib-js/ndarray-base-shape#main", "@stdlib/ndarray-base-strides": "github:stdlib-js/ndarray-base-strides#main", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.1.0" }, "devDependencies": { From 896ce165c1addc2f14387beddf3d081610e66774 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 8 Oct 2023 11:50:24 +0000 Subject: [PATCH 30/91] Remove files --- index.d.ts | 80 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4044 ------------------------------------------------- 4 files changed, 4129 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 a0d0239..0000000 --- a/index.d.ts +++ /dev/null @@ -1,80 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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. -* -* ## Notes -* -* - The function throws an error if a provided ndarray is incompatible with a provided shape. -* - The 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. -* - The returned array is a "base" ndarray, and, thus, the returned array 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 always returns a new ndarray instance even if the input ndarray shape and the desired shape are the same. -* -* @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 -* @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 = broadcastArray( 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 broadcastArray( arr: ndarray, shape: ArrayLike ): ndarray; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = broadcastArray; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 02a38d0..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-ctor@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function e(r){var t,e;for(t=[],e=0;e=0;l--)if(!((m=a-h+l)<0)){if(j=f[m],0!==(i=n[l])&&i\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction broadcastArray( arr, shape ) {\n\tvar strides;\n\tvar dim;\n\tvar sh;\n\tvar st;\n\tvar N;\n\tvar M;\n\tvar d;\n\tvar i;\n\tvar j;\n\n\tN = shape.length;\n\tsh = arr.shape;\n\tM = sh.length;\n\tif ( N < M ) {\n\t\tthrow new Error( format( '0Lx0Z' ) );\n\t}\n\t// Initialize a strides array...\n\tstrides = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tstrides.push( 0 );\n\t}\n\t// Determine the output array strides...\n\tst = arr.strides;\n\tfor ( i = N-1; i >= 0; i-- ) {\n\t\tj = M - N + i;\n\t\tif ( j < 0 ) {\n\t\t\t// Prepended singleton dimension; stride is zero...\n\t\t\tcontinue;\n\t\t}\n\t\td = sh[ j ];\n\t\tdim = shape[ i ];\n\t\tif ( dim !== 0 && dim < d ) {\n\t\t\tthrow new Error( format( '0Lx5T', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t\tif ( d === dim ) {\n\t\t\tstrides[ i ] = st[ j ];\n\t\t} else if ( d === 1 ) {\n\t\t\t// In order to broadcast dimensions, we set the stride for that dimension to zero...\n\t\t\tstrides[ i ] = 0;\n\t\t} else {\n\t\t\t// At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when \"tiling\" an array; e.g., `dim=4` and `d=2`)...\n\t\t\tthrow new Error( format( '0Lx5U', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t}\n\treturn ndarray( arr.dtype, arr.data, copy( shape ), strides, arr.offset, arr.order ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nexport default broadcastArray;\n"],"names":["copyArray","arr","out","i","length","push","broadcastArray","shape","strides","dim","sh","st","N","M","d","j","Error","format","copy","join","ndarray","dtype","data","offset","order"],"mappings":";;sLAsCA,SAASA,EAAWC,GACnB,IAAIC,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAIF,EAAIG,OAAQD,IAC5BD,EAAIG,KAAMJ,EAAKE,IAEhB,OAAOD,CACR,CCsCA,SAASI,EAAgBL,EAAKM,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAX,EACAY,EAKJ,IAHAH,EAAIL,EAAMH,SAEVS,GADAH,EAAKT,EAAIM,OACFH,QAEN,MAAM,IAAIY,MAAOC,EAAQ,UAI1B,IADAT,EAAU,GACJL,EAAI,EAAGA,EAAIS,EAAGT,IACnBK,EAAQH,KAAM,GAIf,IADAM,EAAKV,EAAIO,QACHL,EAAIS,EAAE,EAAGT,GAAK,EAAGA,IAEtB,MADAY,EAAIF,EAAID,EAAIT,GACH,GAAT,CAMA,GAFAW,EAAIJ,EAAIK,GAEK,KADbN,EAAMF,EAAOJ,KACKM,EAAMK,EACvB,MAAM,IAAIE,MAAOC,EAAQ,QAASC,EAAMR,GAAKS,KAAM,MAAQD,EAAMX,GAAQY,KAAM,MAAQhB,IAExF,GAAKW,IAAML,EACVD,EAASL,GAAMQ,EAAII,OACb,IAAW,IAAND,EAKX,MAAM,IAAIE,MAAOC,EAAQ,QAASC,EAAMR,GAAKS,KAAM,MAAQD,EAAMX,GAAQY,KAAM,MAAQhB,IAHvFK,EAASL,GAAM,CAIf,CAdA,CAgBF,OAAOiB,EAASnB,EAAIoB,MAAOpB,EAAIqB,KAAMJ,EAAMX,GAASC,EAASP,EAAIsB,OAAQtB,EAAIuB,MAC9E"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 9dc9c3b..0000000 --- a/stats.html +++ /dev/null @@ -1,4044 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 072781eb59a29b39d575091cc7aa1dfc1085d0b7 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 8 Oct 2023 11:51:39 +0000 Subject: [PATCH 31/91] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 247 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 47 +- benchmark/benchmark.js | 161 - 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 | 65 - docs/types/test.ts | 94 - examples/index.js | 49 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 68 - lib/main.js | 143 - package.json | 67 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 511 -- test/test.js | 511 -- 42 files changed, 6205 insertions(+), 5032 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 (96%) 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 6c59584..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-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 7ab66d5..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-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 7298cd9..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: '28 4 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -175,7 +168,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]. @@ -235,11 +228,11 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-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 7983cf3..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,161 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 broadcastArray = 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 = broadcastArray( 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', 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 = broadcastArray( 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', 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 = broadcastArray( 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(); -}); diff --git a/benchmark/benchmark.ndims.js b/benchmark/benchmark.ndims.js deleted file mode 100644 index 1b81352..0000000 --- a/benchmark/benchmark.ndims.js +++ /dev/null @@ -1,110 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 broadcastArray = 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 = broadcastArray( 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 3167f96..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-array" -%% click B href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-array -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-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 a9d3107..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import broadcastArray from '../docs/types/index'; -export = broadcastArray; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 1bc6139..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var m=function(a,r){return function(){return r||a((r={exports:{}}).exports,r),r.exports}};var c=m(function(x,f){ -var t=require('@stdlib/array-base-copy-indexed/dist'),g=require('@stdlib/ndarray-base-ctor/dist'),l=require('@stdlib/ndarray-base-shape/dist'),y=require('@stdlib/ndarray-base-strides/dist'),q=require('@stdlib/ndarray-base-offset/dist'),b=require('@stdlib/ndarray-base-order/dist'),w=require('@stdlib/ndarray-base-dtype/dist'),D=require('@stdlib/ndarray-base-data-buffer/dist'),p=require('@stdlib/error-tools-fmtprodmsg/dist');function j(a,r){var i,o,s,v,n,u,d,e,h;if(n=r.length,s=l(a,!1),u=s.length,n=0;e--)if(h=u-n+e,!(h<0)){if(d=s[h],o=r[e],o!==0&&o\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction broadcastArray( arr, shape ) {\n\tvar strides;\n\tvar dim;\n\tvar sh;\n\tvar st;\n\tvar N;\n\tvar M;\n\tvar d;\n\tvar i;\n\tvar j;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\tM = sh.length;\n\tif ( N < M ) {\n\t\tthrow new Error( 'invalid argument. Cannot broadcast an array to a shape having fewer dimensions. Arrays can only be broadcasted to shapes having the same or more dimensions.' );\n\t}\n\t// Initialize a strides array...\n\tstrides = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tstrides.push( 0 );\n\t}\n\t// Determine the output array strides...\n\tst = getStrides( arr, false );\n\tfor ( i = N-1; i >= 0; i-- ) {\n\t\tj = M - N + i;\n\t\tif ( j < 0 ) {\n\t\t\t// Prepended singleton dimension; stride is zero...\n\t\t\tcontinue;\n\t\t}\n\t\td = sh[ j ];\n\t\tdim = shape[ i ];\n\t\tif ( dim !== 0 && dim < d ) {\n\t\t\tthrow new Error( format( 'invalid argument. Input array cannot be broadcast to the specified shape, as the specified shape has a dimension whose size is less than the size of the corresponding dimension in the input array. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t\tif ( d === dim ) {\n\t\t\tstrides[ i ] = st[ j ];\n\t\t} else if ( d === 1 ) {\n\t\t\t// In order to broadcast dimensions, we set the stride for that dimension to zero...\n\t\t\tstrides[ i ] = 0;\n\t\t} else {\n\t\t\t// At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when \"tiling\" an array; e.g., `dim=4` and `d=2`)...\n\t\t\tthrow new Error( format( 'invalid argument. Input array and the specified shape are broadcast incompatible. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t}\n\treturn ndarray( getDType( arr ), getData( arr ), copy( shape ), strides, getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nmodule.exports = broadcastArray;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast an ndarray to a specified shape.\n*\n* @module @stdlib/ndarray-base-broadcast-array\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var broadcastArray = require( '@stdlib/ndarray-base-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 = broadcastArray( 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,EAAO,QAAS,iCAAkC,EAClDC,EAAU,QAAS,2BAA4B,EAC/CC,EAAW,QAAS,4BAA6B,EACjDC,EAAa,QAAQ,8BAA+B,EACpDC,EAAY,QAAS,6BAA8B,EACnDC,EAAW,QAAS,4BAA6B,EACjDC,EAAW,QAAS,4BAA6B,EACjDC,EAAU,QAAS,kCAAmC,EACtDC,EAAS,QAAS,uBAAwB,EA6D9C,SAASC,EAAgBC,EAAKC,EAAQ,CACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACA,EACAC,EACAC,EAKJ,GAHAH,EAAIL,EAAM,OACVG,EAAKZ,EAAUQ,EAAK,EAAM,EAC1BO,EAAIH,EAAG,OACFE,EAAIC,EACR,MAAM,IAAI,MAAO,8JAA+J,EAIjL,IADAL,EAAU,CAAC,EACLM,EAAI,EAAGA,EAAIF,EAAGE,IACnBN,EAAQ,KAAM,CAAE,EAIjB,IADAG,EAAKZ,EAAYO,EAAK,EAAM,EACtBQ,EAAIF,EAAE,EAAGE,GAAK,EAAGA,IAEtB,GADAC,EAAIF,EAAID,EAAIE,EACP,EAAAC,EAAI,GAMT,IAFA,EAAIL,EAAIK,CAAE,EACVN,EAAMF,EAAOO,CAAE,EACVL,IAAQ,GAAKA,EAAM,EACvB,MAAM,IAAI,MAAOL,EAAQ,8PAA+PR,EAAMc,CAAG,EAAE,KAAM,IAAK,EAAGd,EAAMW,CAAM,EAAE,KAAM,IAAK,EAAGO,CAAE,CAAE,EAElV,GAAK,IAAML,EACVD,EAASM,CAAE,EAAIH,EAAII,CAAE,UACV,IAAM,EAEjBP,EAASM,CAAE,EAAI,MAGf,OAAM,IAAI,MAAOV,EAAQ,2IAA4IR,EAAMc,CAAG,EAAE,KAAM,IAAK,EAAGd,EAAMW,CAAM,EAAE,KAAM,IAAK,EAAGO,CAAE,CAAE,EAGhO,OAAOjB,EAASK,EAAUI,CAAI,EAAGH,EAASG,CAAI,EAAGV,EAAMW,CAAM,EAAGC,EAASR,EAAWM,CAAI,EAAGL,EAAUK,CAAI,CAAE,CAC5G,CAKAX,EAAO,QAAUU,IChFjB,IAAIW,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "copy", "ndarray", "getShape", "getStrides", "getOffset", "getOrder", "getDType", "getData", "format", "broadcastArray", "arr", "shape", "strides", "dim", "sh", "st", "N", "M", "i", "j", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index db0f44c..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,65 +0,0 @@ - -{{alias}}( arr, shape ) - Broadcasts an ndarray to a specified shape. - - The 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. - - The returned array is a "base" ndarray, and, thus, the returned array 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. - - The function always returns a new ndarray instance even if the input ndarray - shape and the desired shape are the same. - - 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 4041dc7..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,94 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 broadcastArray = 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(); - - broadcastArray( x, [ 2, 2, 2 ] ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is not provided a first argument which is an ndarray... -{ - broadcastArray( '5', [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( 5, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( true, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( false, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( null, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( {}, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( [ '5' ], [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( ( 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(); - - broadcastArray( x, '5' ); // $ExpectError - broadcastArray( x, 5 ); // $ExpectError - broadcastArray( x, true ); // $ExpectError - broadcastArray( x, false ); // $ExpectError - broadcastArray( x, null ); // $ExpectError - broadcastArray( x, {} ); // $ExpectError - broadcastArray( x, [ '5' ] ); // $ExpectError - broadcastArray( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - - broadcastArray(); // $ExpectError - broadcastArray( x ); // $ExpectError - broadcastArray( x, [ 1, 2, 3 ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index f0dc7b6..0000000 --- a/examples/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 broadcastArray = require( './../lib' ); - -// Create a 2x2 array: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -// returns - -// Broadcast the array to 3x2x2: -var y = broadcastArray( 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 sub; -var v; -var i; -for ( i = 0; i < N; i++ ) { - v = y.iget( i ); - sub = ind2sub( sh, i ); - console.log( 'Y[%s] = %d', sub.join( ', ' ), v ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index 2469a52..d30c131 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..5bfc547 --- /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 s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy-indexed@v0.1.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function m(m,h){var p,j,f,l,b,c,g,v,y;if((b=h.length)<(c=(f=r(m,!1)).length))throw new Error("invalid argument. Cannot broadcast an array to a shape having fewer dimensions. Arrays can only be broadcasted to shapes having the same or more dimensions.");for(p=[],v=0;v=0;v--)if(!((y=c-b+v)<0)){if(g=f[y],0!==(j=h[v])&&j\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction broadcastArray( arr, shape ) {\n\tvar strides;\n\tvar dim;\n\tvar sh;\n\tvar st;\n\tvar N;\n\tvar M;\n\tvar d;\n\tvar i;\n\tvar j;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\tM = sh.length;\n\tif ( N < M ) {\n\t\tthrow new Error( 'invalid argument. Cannot broadcast an array to a shape having fewer dimensions. Arrays can only be broadcasted to shapes having the same or more dimensions.' );\n\t}\n\t// Initialize a strides array...\n\tstrides = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tstrides.push( 0 );\n\t}\n\t// Determine the output array strides...\n\tst = getStrides( arr, false );\n\tfor ( i = N-1; i >= 0; i-- ) {\n\t\tj = M - N + i;\n\t\tif ( j < 0 ) {\n\t\t\t// Prepended singleton dimension; stride is zero...\n\t\t\tcontinue;\n\t\t}\n\t\td = sh[ j ];\n\t\tdim = shape[ i ];\n\t\tif ( dim !== 0 && dim < d ) {\n\t\t\tthrow new Error( format( 'invalid argument. Input array cannot be broadcast to the specified shape, as the specified shape has a dimension whose size is less than the size of the corresponding dimension in the input array. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t\tif ( d === dim ) {\n\t\t\tstrides[ i ] = st[ j ];\n\t\t} else if ( d === 1 ) {\n\t\t\t// In order to broadcast dimensions, we set the stride for that dimension to zero...\n\t\t\tstrides[ i ] = 0;\n\t\t} else {\n\t\t\t// At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when \"tiling\" an array; e.g., `dim=4` and `d=2`)...\n\t\t\tthrow new Error( format( 'invalid argument. Input array and the specified shape are broadcast incompatible. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t}\n\treturn ndarray( getDType( arr ), getData( arr ), copy( shape ), strides, getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nexport default broadcastArray;\n"],"names":["broadcastArray","arr","shape","strides","dim","sh","st","N","M","d","i","j","length","getShape","Error","push","getStrides","format","copy","join","ndarray","getDType","getData","getOffset","getOrder"],"mappings":";;myBA2FA,SAASA,EAAgBC,EAAKC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAJ,EAAIL,EAAMU,SAEVJ,GADAH,EAAKQ,EAAUZ,GAAK,IACbW,QAEN,MAAM,IAAIE,MAAO,gKAIlB,IADAX,EAAU,GACJO,EAAI,EAAGA,EAAIH,EAAGG,IACnBP,EAAQY,KAAM,GAIf,IADAT,EAAKU,EAAYf,GAAK,GAChBS,EAAIH,EAAE,EAAGG,GAAK,EAAGA,IAEtB,MADAC,EAAIH,EAAID,EAAIG,GACH,GAAT,CAMA,GAFAD,EAAIJ,EAAIM,GAEK,KADbP,EAAMF,EAAOQ,KACKN,EAAMK,EACvB,MAAM,IAAIK,MAAOG,EAAQ,8PAA+PC,EAAMb,GAAKc,KAAM,MAAQD,EAAMhB,GAAQiB,KAAM,MAAQT,IAE9U,GAAKD,IAAML,EACVD,EAASO,GAAMJ,EAAIK,OACb,IAAW,IAANF,EAKX,MAAM,IAAIK,MAAOG,EAAQ,2IAA4IC,EAAMb,GAAKc,KAAM,MAAQD,EAAMhB,GAAQiB,KAAM,MAAQT,IAH1NP,EAASO,GAAM,CAIf,CAdA,CAgBF,OAAOU,EAASC,EAAUpB,GAAOqB,EAASrB,GAAOiB,EAAMhB,GAASC,EAASoB,EAAWtB,GAAOuB,EAAUvB,GACtG"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index b6aaa86..0000000 --- a/lib/index.js +++ /dev/null @@ -1,68 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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. -* -* @module @stdlib/ndarray-base-broadcast-array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var broadcastArray = require( '@stdlib/ndarray-base-broadcast-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = broadcastArray( 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 20e9b81..0000000 --- a/lib/main.js +++ /dev/null @@ -1,143 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var copy = require( '@stdlib/array-base-copy-indexed' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require('@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var format = require( '@stdlib/string-format' ); - - -// MAIN // - -/** -* Broadcasts an ndarray to a specified shape. -* -* ## Notes -* -* - The 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. -* -* @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 = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] ); -* // throws -*/ -function broadcastArray( arr, shape ) { - var strides; - var dim; - var sh; - var st; - var N; - var M; - var d; - var i; - var j; - - N = shape.length; - sh = getShape( arr, false ); - M = sh.length; - if ( N < M ) { - throw new Error( 'invalid argument. Cannot broadcast an array to a shape having fewer dimensions. Arrays can only be broadcasted to shapes having the same or more dimensions.' ); - } - // Initialize a strides array... - strides = []; - for ( i = 0; i < N; i++ ) { - strides.push( 0 ); - } - // Determine the output array strides... - st = getStrides( arr, false ); - for ( i = N-1; i >= 0; i-- ) { - j = M - N + i; - if ( j < 0 ) { - // Prepended singleton dimension; stride is zero... - continue; - } - d = sh[ j ]; - dim = shape[ i ]; - if ( dim !== 0 && dim < d ) { - throw new Error( format( 'invalid argument. Input array cannot be broadcast to the specified shape, as the specified shape has a dimension whose size is less than the size of the corresponding dimension in the input array. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); - } - if ( d === dim ) { - strides[ i ] = st[ j ]; - } else if ( d === 1 ) { - // In order to broadcast dimensions, we set the stride for that dimension to zero... - strides[ i ] = 0; - } else { - // At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when "tiling" an array; e.g., `dim=4` and `d=2`)... - throw new Error( format( 'invalid argument. Input array and the specified shape are broadcast incompatible. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); - } - } - return ndarray( getDType( arr ), getData( arr ), copy( shape ), strides, getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len -} - - -// EXPORTS // - -module.exports = broadcastArray; diff --git a/package.json b/package.json index fee8cb9..a421f20 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Broadcast an ndarray to a specified 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,45 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-copy-indexed": "^0.1.0", - "@stdlib/ndarray-base-ctor": "^0.1.0", - "@stdlib/ndarray-base-data-buffer": "github:stdlib-js/ndarray-base-data-buffer#main", - "@stdlib/ndarray-base-dtype": "github:stdlib-js/ndarray-base-dtype#main", - "@stdlib/ndarray-base-offset": "github:stdlib-js/ndarray-base-offset#main", - "@stdlib/ndarray-base-order": "github:stdlib-js/ndarray-base-order#main", - "@stdlib/ndarray-base-shape": "github:stdlib-js/ndarray-base-shape#main", - "@stdlib/ndarray-base-strides": "github:stdlib-js/ndarray-base-strides#main", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^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-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", @@ -91,7 +29,6 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..b5378ae --- /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 02e4272..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,511 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 broadcastArray = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastArray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a desired shape which has fewer dimensions than 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() { - broadcastArray( 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() { - broadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape and an input array shape 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() { - broadcastArray( x, value ); - }; - } -}); - -tape( 'the function returns a "base" ndarray instance', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = broadcastArray( 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 = broadcastArray( 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.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, 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 = broadcastArray( x, expected ); - - actual = y.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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 97decdb..0000000 --- a/test/test.js +++ /dev/null @@ -1,511 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 broadcastArray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastArray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a desired shape which has fewer dimensions than 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() { - broadcastArray( 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() { - broadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape and an input array shape 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() { - broadcastArray( x, value ); - }; - } -}); - -tape( 'the function returns a "base" ndarray instance', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = broadcastArray( 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 = broadcastArray( 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.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, 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 = broadcastArray( x, expected ); - - actual = y.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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 1956ca45e25fb49463c6551b65d5045da36af95c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 07:55:17 +0000 Subject: [PATCH 32/91] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 5fcc931..e8dae63 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "@stdlib/ndarray-base-order": "^0.1.0", "@stdlib/ndarray-base-shape": "^0.1.0", "@stdlib/ndarray-base-strides": "^0.1.0", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.2.0" }, "devDependencies": { From 2641505f3644f36c115decc3fbc0d846230c1e62 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 14:31:26 +0000 Subject: [PATCH 33/91] Remove files --- index.d.ts | 80 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6262 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 d30c131..0000000 --- a/index.d.ts +++ /dev/null @@ -1,80 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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. -* -* ## Notes -* -* - The function throws an error if a provided ndarray is incompatible with a provided shape. -* - The 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. -* - The returned array is a "base" ndarray, and, thus, the returned array 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 always returns a new ndarray instance even if the input ndarray shape and the desired shape are the same. -* -* @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 -* @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 = broadcastArray( 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 broadcastArray( arr: ndarray, shape: ArrayLike ): ndarray; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = broadcastArray; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 5bfc547..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 s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy-indexed@v0.1.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function m(m,h){var p,j,f,l,b,c,g,v,y;if((b=h.length)<(c=(f=r(m,!1)).length))throw new Error("invalid argument. Cannot broadcast an array to a shape having fewer dimensions. Arrays can only be broadcasted to shapes having the same or more dimensions.");for(p=[],v=0;v=0;v--)if(!((y=c-b+v)<0)){if(g=f[y],0!==(j=h[v])&&j\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction broadcastArray( arr, shape ) {\n\tvar strides;\n\tvar dim;\n\tvar sh;\n\tvar st;\n\tvar N;\n\tvar M;\n\tvar d;\n\tvar i;\n\tvar j;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\tM = sh.length;\n\tif ( N < M ) {\n\t\tthrow new Error( 'invalid argument. Cannot broadcast an array to a shape having fewer dimensions. Arrays can only be broadcasted to shapes having the same or more dimensions.' );\n\t}\n\t// Initialize a strides array...\n\tstrides = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tstrides.push( 0 );\n\t}\n\t// Determine the output array strides...\n\tst = getStrides( arr, false );\n\tfor ( i = N-1; i >= 0; i-- ) {\n\t\tj = M - N + i;\n\t\tif ( j < 0 ) {\n\t\t\t// Prepended singleton dimension; stride is zero...\n\t\t\tcontinue;\n\t\t}\n\t\td = sh[ j ];\n\t\tdim = shape[ i ];\n\t\tif ( dim !== 0 && dim < d ) {\n\t\t\tthrow new Error( format( 'invalid argument. Input array cannot be broadcast to the specified shape, as the specified shape has a dimension whose size is less than the size of the corresponding dimension in the input array. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t\tif ( d === dim ) {\n\t\t\tstrides[ i ] = st[ j ];\n\t\t} else if ( d === 1 ) {\n\t\t\t// In order to broadcast dimensions, we set the stride for that dimension to zero...\n\t\t\tstrides[ i ] = 0;\n\t\t} else {\n\t\t\t// At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when \"tiling\" an array; e.g., `dim=4` and `d=2`)...\n\t\t\tthrow new Error( format( 'invalid argument. Input array and the specified shape are broadcast incompatible. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t}\n\treturn ndarray( getDType( arr ), getData( arr ), copy( shape ), strides, getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nexport default broadcastArray;\n"],"names":["broadcastArray","arr","shape","strides","dim","sh","st","N","M","d","i","j","length","getShape","Error","push","getStrides","format","copy","join","ndarray","getDType","getData","getOffset","getOrder"],"mappings":";;myBA2FA,SAASA,EAAgBC,EAAKC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAJ,EAAIL,EAAMU,SAEVJ,GADAH,EAAKQ,EAAUZ,GAAK,IACbW,QAEN,MAAM,IAAIE,MAAO,gKAIlB,IADAX,EAAU,GACJO,EAAI,EAAGA,EAAIH,EAAGG,IACnBP,EAAQY,KAAM,GAIf,IADAT,EAAKU,EAAYf,GAAK,GAChBS,EAAIH,EAAE,EAAGG,GAAK,EAAGA,IAEtB,MADAC,EAAIH,EAAID,EAAIG,GACH,GAAT,CAMA,GAFAD,EAAIJ,EAAIM,GAEK,KADbP,EAAMF,EAAOQ,KACKN,EAAMK,EACvB,MAAM,IAAIK,MAAOG,EAAQ,8PAA+PC,EAAMb,GAAKc,KAAM,MAAQD,EAAMhB,GAAQiB,KAAM,MAAQT,IAE9U,GAAKD,IAAML,EACVD,EAASO,GAAMJ,EAAIK,OACb,IAAW,IAANF,EAKX,MAAM,IAAIK,MAAOG,EAAQ,2IAA4IC,EAAMb,GAAKc,KAAM,MAAQD,EAAMhB,GAAQiB,KAAM,MAAQT,IAH1NP,EAASO,GAAM,CAIf,CAdA,CAgBF,OAAOU,EAASC,EAAUpB,GAAOqB,EAASrB,GAAOiB,EAAMhB,GAASC,EAASoB,EAAWtB,GAAOuB,EAAUvB,GACtG"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index b5378ae..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 96b8a952f2add9ff9c303110d9f7216913f5b209 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 14:32:01 +0000 Subject: [PATCH 34/91] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 228 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 47 +- SECURITY.md | 5 - benchmark/benchmark.js | 161 - 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 | 65 - docs/types/test.ts | 94 - examples/index.js | 49 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 68 - lib/main.js | 143 - package.json | 67 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 511 -- 44 files changed, 6205 insertions(+), 4564 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 (96%) 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 8efe688..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-01-01T05:05:39.408Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 6c59584..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-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 7ab66d5..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-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 c175b42..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: '28 4 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index e1e3539..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -175,7 +168,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]. @@ -235,11 +228,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-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 d0243ca..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,161 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 broadcastArray = 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 = broadcastArray( 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', 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 = broadcastArray( 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', 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 = broadcastArray( 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(); -}); diff --git a/benchmark/benchmark.ndims.js b/benchmark/benchmark.ndims.js deleted file mode 100644 index 9530251..0000000 --- a/benchmark/benchmark.ndims.js +++ /dev/null @@ -1,110 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 broadcastArray = 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 = broadcastArray( 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 3167f96..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-array" -%% click B href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-array -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-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 a9d3107..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import broadcastArray from '../docs/types/index'; -export = broadcastArray; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index e7736e3..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var m=function(a,r){return function(){return r||a((r={exports:{}}).exports,r),r.exports}};var c=m(function(x,f){ -var t=require('@stdlib/array-base-copy-indexed/dist'),g=require('@stdlib/ndarray-base-ctor/dist'),l=require('@stdlib/ndarray-base-shape/dist'),y=require('@stdlib/ndarray-base-strides/dist'),q=require('@stdlib/ndarray-base-offset/dist'),b=require('@stdlib/ndarray-base-order/dist'),w=require('@stdlib/ndarray-base-dtype/dist'),D=require('@stdlib/ndarray-base-data-buffer/dist'),p=require('@stdlib/error-tools-fmtprodmsg/dist');function j(a,r){var i,o,s,v,n,u,d,e,h;if(n=r.length,s=l(a,!1),u=s.length,n=0;e--)if(h=u-n+e,!(h<0)){if(d=s[h],o=r[e],o!==0&&o\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction broadcastArray( arr, shape ) {\n\tvar strides;\n\tvar dim;\n\tvar sh;\n\tvar st;\n\tvar N;\n\tvar M;\n\tvar d;\n\tvar i;\n\tvar j;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\tM = sh.length;\n\tif ( N < M ) {\n\t\tthrow new Error( 'invalid argument. Cannot broadcast an array to a shape having fewer dimensions. Arrays can only be broadcasted to shapes having the same or more dimensions.' );\n\t}\n\t// Initialize a strides array...\n\tstrides = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tstrides.push( 0 );\n\t}\n\t// Determine the output array strides...\n\tst = getStrides( arr, false );\n\tfor ( i = N-1; i >= 0; i-- ) {\n\t\tj = M - N + i;\n\t\tif ( j < 0 ) {\n\t\t\t// Prepended singleton dimension; stride is zero...\n\t\t\tcontinue;\n\t\t}\n\t\td = sh[ j ];\n\t\tdim = shape[ i ];\n\t\tif ( dim !== 0 && dim < d ) {\n\t\t\tthrow new Error( format( 'invalid argument. Input array cannot be broadcast to the specified shape, as the specified shape has a dimension whose size is less than the size of the corresponding dimension in the input array. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t\tif ( d === dim ) {\n\t\t\tstrides[ i ] = st[ j ];\n\t\t} else if ( d === 1 ) {\n\t\t\t// In order to broadcast dimensions, we set the stride for that dimension to zero...\n\t\t\tstrides[ i ] = 0;\n\t\t} else {\n\t\t\t// At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when \"tiling\" an array; e.g., `dim=4` and `d=2`)...\n\t\t\tthrow new Error( format( 'invalid argument. Input array and the specified shape are broadcast incompatible. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t}\n\treturn ndarray( getDType( arr ), getData( arr ), copy( shape ), strides, getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nmodule.exports = broadcastArray;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast an ndarray to a specified shape.\n*\n* @module @stdlib/ndarray-base-broadcast-array\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var broadcastArray = require( '@stdlib/ndarray-base-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 = broadcastArray( 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,EAAO,QAAS,iCAAkC,EAClDC,EAAU,QAAS,2BAA4B,EAC/CC,EAAW,QAAS,4BAA6B,EACjDC,EAAa,QAAQ,8BAA+B,EACpDC,EAAY,QAAS,6BAA8B,EACnDC,EAAW,QAAS,4BAA6B,EACjDC,EAAW,QAAS,4BAA6B,EACjDC,EAAU,QAAS,kCAAmC,EACtDC,EAAS,QAAS,uBAAwB,EA6D9C,SAASC,EAAgBC,EAAKC,EAAQ,CACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACA,EACAC,EACAC,EAKJ,GAHAH,EAAIL,EAAM,OACVG,EAAKZ,EAAUQ,EAAK,EAAM,EAC1BO,EAAIH,EAAG,OACFE,EAAIC,EACR,MAAM,IAAI,MAAO,8JAA+J,EAIjL,IADAL,EAAU,CAAC,EACLM,EAAI,EAAGA,EAAIF,EAAGE,IACnBN,EAAQ,KAAM,CAAE,EAIjB,IADAG,EAAKZ,EAAYO,EAAK,EAAM,EACtBQ,EAAIF,EAAE,EAAGE,GAAK,EAAGA,IAEtB,GADAC,EAAIF,EAAID,EAAIE,EACP,EAAAC,EAAI,GAMT,IAFA,EAAIL,EAAIK,CAAE,EACVN,EAAMF,EAAOO,CAAE,EACVL,IAAQ,GAAKA,EAAM,EACvB,MAAM,IAAI,MAAOL,EAAQ,8PAA+PR,EAAMc,CAAG,EAAE,KAAM,IAAK,EAAGd,EAAMW,CAAM,EAAE,KAAM,IAAK,EAAGO,CAAE,CAAE,EAElV,GAAK,IAAML,EACVD,EAASM,CAAE,EAAIH,EAAII,CAAE,UACV,IAAM,EAEjBP,EAASM,CAAE,EAAI,MAGf,OAAM,IAAI,MAAOV,EAAQ,2IAA4IR,EAAMc,CAAG,EAAE,KAAM,IAAK,EAAGd,EAAMW,CAAM,EAAE,KAAM,IAAK,EAAGO,CAAE,CAAE,EAGhO,OAAOjB,EAASK,EAAUI,CAAI,EAAGH,EAASG,CAAI,EAAGV,EAAMW,CAAM,EAAGC,EAASR,EAAWM,CAAI,EAAGL,EAAUK,CAAI,CAAE,CAC5G,CAKAX,EAAO,QAAUU,IChFjB,IAAIW,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "copy", "ndarray", "getShape", "getStrides", "getOffset", "getOrder", "getDType", "getData", "format", "broadcastArray", "arr", "shape", "strides", "dim", "sh", "st", "N", "M", "i", "j", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index db0f44c..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,65 +0,0 @@ - -{{alias}}( arr, shape ) - Broadcasts an ndarray to a specified shape. - - The 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. - - The returned array is a "base" ndarray, and, thus, the returned array 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. - - The function always returns a new ndarray instance even if the input ndarray - shape and the desired shape are the same. - - 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 4041dc7..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,94 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 broadcastArray = 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(); - - broadcastArray( x, [ 2, 2, 2 ] ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is not provided a first argument which is an ndarray... -{ - broadcastArray( '5', [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( 5, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( true, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( false, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( null, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( {}, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( [ '5' ], [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( ( 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(); - - broadcastArray( x, '5' ); // $ExpectError - broadcastArray( x, 5 ); // $ExpectError - broadcastArray( x, true ); // $ExpectError - broadcastArray( x, false ); // $ExpectError - broadcastArray( x, null ); // $ExpectError - broadcastArray( x, {} ); // $ExpectError - broadcastArray( x, [ '5' ] ); // $ExpectError - broadcastArray( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - - broadcastArray(); // $ExpectError - broadcastArray( x ); // $ExpectError - broadcastArray( x, [ 1, 2, 3 ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index f0dc7b6..0000000 --- a/examples/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 broadcastArray = require( './../lib' ); - -// Create a 2x2 array: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -// returns - -// Broadcast the array to 3x2x2: -var y = broadcastArray( 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 sub; -var v; -var i; -for ( i = 0; i < N; i++ ) { - v = y.iget( i ); - sub = ind2sub( sh, i ); - console.log( 'Y[%s] = %d', sub.join( ', ' ), v ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index 8a81be0..69a2154 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..db51810 --- /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 s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy-indexed@v0.1.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function m(m,h){var p,j,f,l,b,v,c,g,y;if((b=h.length)<(v=(f=r(m,!1)).length))throw new Error("invalid argument. Cannot broadcast an array to a shape having fewer dimensions. Arrays can only be broadcasted to shapes having the same or more dimensions.");for(p=[],g=0;g=0;g--)if(!((y=v-b+g)<0)){if(c=f[y],0!==(j=h[g])&&j\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction broadcastArray( arr, shape ) {\n\tvar strides;\n\tvar dim;\n\tvar sh;\n\tvar st;\n\tvar N;\n\tvar M;\n\tvar d;\n\tvar i;\n\tvar j;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\tM = sh.length;\n\tif ( N < M ) {\n\t\tthrow new Error( 'invalid argument. Cannot broadcast an array to a shape having fewer dimensions. Arrays can only be broadcasted to shapes having the same or more dimensions.' );\n\t}\n\t// Initialize a strides array...\n\tstrides = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tstrides.push( 0 );\n\t}\n\t// Determine the output array strides...\n\tst = getStrides( arr, false );\n\tfor ( i = N-1; i >= 0; i-- ) {\n\t\tj = M - N + i;\n\t\tif ( j < 0 ) {\n\t\t\t// Prepended singleton dimension; stride is zero...\n\t\t\tcontinue;\n\t\t}\n\t\td = sh[ j ];\n\t\tdim = shape[ i ];\n\t\tif ( dim !== 0 && dim < d ) {\n\t\t\tthrow new Error( format( 'invalid argument. Input array cannot be broadcast to the specified shape, as the specified shape has a dimension whose size is less than the size of the corresponding dimension in the input array. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t\tif ( d === dim ) {\n\t\t\tstrides[ i ] = st[ j ];\n\t\t} else if ( d === 1 ) {\n\t\t\t// In order to broadcast dimensions, we set the stride for that dimension to zero...\n\t\t\tstrides[ i ] = 0;\n\t\t} else {\n\t\t\t// At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when \"tiling\" an array; e.g., `dim=4` and `d=2`)...\n\t\t\tthrow new Error( format( 'invalid argument. Input array and the specified shape are broadcast incompatible. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t}\n\treturn ndarray( getDType( arr ), getData( arr ), copy( shape ), strides, getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nexport default broadcastArray;\n"],"names":["broadcastArray","arr","shape","strides","dim","sh","st","N","M","d","i","j","length","getShape","Error","push","getStrides","format","copy","join","ndarray","getDType","getData","getOffset","getOrder"],"mappings":";;60BA2FA,SAASA,EAAgBC,EAAKC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAJ,EAAIL,EAAMU,SAEVJ,GADAH,EAAKQ,EAAUZ,GAAK,IACbW,QAEN,MAAM,IAAIE,MAAO,gKAIlB,IADAX,EAAU,GACJO,EAAI,EAAGA,EAAIH,EAAGG,IACnBP,EAAQY,KAAM,GAIf,IADAT,EAAKU,EAAYf,GAAK,GAChBS,EAAIH,EAAE,EAAGG,GAAK,EAAGA,IAEtB,MADAC,EAAIH,EAAID,EAAIG,GACH,GAAT,CAMA,GAFAD,EAAIJ,EAAIM,GAEK,KADbP,EAAMF,EAAOQ,KACKN,EAAMK,EACvB,MAAM,IAAIK,MAAOG,EAAQ,8PAA+PC,EAAMb,GAAKc,KAAM,MAAQD,EAAMhB,GAAQiB,KAAM,MAAQT,IAE9U,GAAKD,IAAML,EACVD,EAASO,GAAMJ,EAAIK,OACb,IAAW,IAANF,EAKX,MAAM,IAAIK,MAAOG,EAAQ,2IAA4IC,EAAMb,GAAKc,KAAM,MAAQD,EAAMhB,GAAQiB,KAAM,MAAQT,IAH1NP,EAASO,GAAM,CAIf,CAdA,CAgBF,OAAOU,EAASC,EAAUpB,GAAOqB,EAASrB,GAAOiB,EAAMhB,GAASC,EAASoB,EAAWtB,GAAOuB,EAAUvB,GACtG"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index b6aaa86..0000000 --- a/lib/index.js +++ /dev/null @@ -1,68 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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. -* -* @module @stdlib/ndarray-base-broadcast-array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var broadcastArray = require( '@stdlib/ndarray-base-broadcast-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = broadcastArray( 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 20e9b81..0000000 --- a/lib/main.js +++ /dev/null @@ -1,143 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var copy = require( '@stdlib/array-base-copy-indexed' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require('@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var format = require( '@stdlib/string-format' ); - - -// MAIN // - -/** -* Broadcasts an ndarray to a specified shape. -* -* ## Notes -* -* - The 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. -* -* @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 = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] ); -* // throws -*/ -function broadcastArray( arr, shape ) { - var strides; - var dim; - var sh; - var st; - var N; - var M; - var d; - var i; - var j; - - N = shape.length; - sh = getShape( arr, false ); - M = sh.length; - if ( N < M ) { - throw new Error( 'invalid argument. Cannot broadcast an array to a shape having fewer dimensions. Arrays can only be broadcasted to shapes having the same or more dimensions.' ); - } - // Initialize a strides array... - strides = []; - for ( i = 0; i < N; i++ ) { - strides.push( 0 ); - } - // Determine the output array strides... - st = getStrides( arr, false ); - for ( i = N-1; i >= 0; i-- ) { - j = M - N + i; - if ( j < 0 ) { - // Prepended singleton dimension; stride is zero... - continue; - } - d = sh[ j ]; - dim = shape[ i ]; - if ( dim !== 0 && dim < d ) { - throw new Error( format( 'invalid argument. Input array cannot be broadcast to the specified shape, as the specified shape has a dimension whose size is less than the size of the corresponding dimension in the input array. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); - } - if ( d === dim ) { - strides[ i ] = st[ j ]; - } else if ( d === 1 ) { - // In order to broadcast dimensions, we set the stride for that dimension to zero... - strides[ i ] = 0; - } else { - // At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when "tiling" an array; e.g., `dim=4` and `d=2`)... - throw new Error( format( 'invalid argument. Input array and the specified shape are broadcast incompatible. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); - } - } - return ndarray( getDType( arr ), getData( arr ), copy( shape ), strides, getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len -} - - -// EXPORTS // - -module.exports = broadcastArray; diff --git a/package.json b/package.json index e8dae63..a421f20 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Broadcast an ndarray to a specified 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,45 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-copy-indexed": "^0.1.0", - "@stdlib/ndarray-base-ctor": "^0.1.0", - "@stdlib/ndarray-base-data-buffer": "^0.1.0", - "@stdlib/ndarray-base-dtype": "^0.1.0", - "@stdlib/ndarray-base-offset": "^0.1.0", - "@stdlib/ndarray-base-order": "^0.1.0", - "@stdlib/ndarray-base-shape": "^0.1.0", - "@stdlib/ndarray-base-strides": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.2.0" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.1.1", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/ndarray-array": "^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", @@ -91,7 +29,6 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..421366d --- /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 97decdb..0000000 --- a/test/test.js +++ /dev/null @@ -1,511 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 broadcastArray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastArray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a desired shape which has fewer dimensions than 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() { - broadcastArray( 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() { - broadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape and an input array shape 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() { - broadcastArray( x, value ); - }; - } -}); - -tape( 'the function returns a "base" ndarray instance', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = broadcastArray( 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 = broadcastArray( 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.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, 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 = broadcastArray( x, expected ); - - actual = y.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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 32e8e1ef1667a3b8f900294ad3008cad19741f90 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Feb 2024 08:25:39 +0000 Subject: [PATCH 35/91] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 5fcc931..e8dae63 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "@stdlib/ndarray-base-order": "^0.1.0", "@stdlib/ndarray-base-shape": "^0.1.0", "@stdlib/ndarray-base-strides": "^0.1.0", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.2.0" }, "devDependencies": { From ff431d1a5f9dbbf7840d4c41c8b7e30a0de83a66 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Feb 2024 13:48:17 +0000 Subject: [PATCH 36/91] Remove files --- index.d.ts | 80 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6262 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 69a2154..0000000 --- a/index.d.ts +++ /dev/null @@ -1,80 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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. -* -* ## Notes -* -* - The function throws an error if a provided ndarray is incompatible with a provided shape. -* - The 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. -* - The returned array is a "base" ndarray, and, thus, the returned array 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 always returns a new ndarray instance even if the input ndarray shape and the desired shape are the same. -* -* @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 -* @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 = broadcastArray( 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 broadcastArray( arr: ndarray, shape: ArrayLike ): ndarray; - - -// EXPORTS // - -export = broadcastArray; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index db51810..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 s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy-indexed@v0.1.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function m(m,h){var p,j,f,l,b,v,c,g,y;if((b=h.length)<(v=(f=r(m,!1)).length))throw new Error("invalid argument. Cannot broadcast an array to a shape having fewer dimensions. Arrays can only be broadcasted to shapes having the same or more dimensions.");for(p=[],g=0;g=0;g--)if(!((y=v-b+g)<0)){if(c=f[y],0!==(j=h[g])&&j\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction broadcastArray( arr, shape ) {\n\tvar strides;\n\tvar dim;\n\tvar sh;\n\tvar st;\n\tvar N;\n\tvar M;\n\tvar d;\n\tvar i;\n\tvar j;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\tM = sh.length;\n\tif ( N < M ) {\n\t\tthrow new Error( 'invalid argument. Cannot broadcast an array to a shape having fewer dimensions. Arrays can only be broadcasted to shapes having the same or more dimensions.' );\n\t}\n\t// Initialize a strides array...\n\tstrides = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tstrides.push( 0 );\n\t}\n\t// Determine the output array strides...\n\tst = getStrides( arr, false );\n\tfor ( i = N-1; i >= 0; i-- ) {\n\t\tj = M - N + i;\n\t\tif ( j < 0 ) {\n\t\t\t// Prepended singleton dimension; stride is zero...\n\t\t\tcontinue;\n\t\t}\n\t\td = sh[ j ];\n\t\tdim = shape[ i ];\n\t\tif ( dim !== 0 && dim < d ) {\n\t\t\tthrow new Error( format( 'invalid argument. Input array cannot be broadcast to the specified shape, as the specified shape has a dimension whose size is less than the size of the corresponding dimension in the input array. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t\tif ( d === dim ) {\n\t\t\tstrides[ i ] = st[ j ];\n\t\t} else if ( d === 1 ) {\n\t\t\t// In order to broadcast dimensions, we set the stride for that dimension to zero...\n\t\t\tstrides[ i ] = 0;\n\t\t} else {\n\t\t\t// At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when \"tiling\" an array; e.g., `dim=4` and `d=2`)...\n\t\t\tthrow new Error( format( 'invalid argument. Input array and the specified shape are broadcast incompatible. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t}\n\treturn ndarray( getDType( arr ), getData( arr ), copy( shape ), strides, getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nexport default broadcastArray;\n"],"names":["broadcastArray","arr","shape","strides","dim","sh","st","N","M","d","i","j","length","getShape","Error","push","getStrides","format","copy","join","ndarray","getDType","getData","getOffset","getOrder"],"mappings":";;60BA2FA,SAASA,EAAgBC,EAAKC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAJ,EAAIL,EAAMU,SAEVJ,GADAH,EAAKQ,EAAUZ,GAAK,IACbW,QAEN,MAAM,IAAIE,MAAO,gKAIlB,IADAX,EAAU,GACJO,EAAI,EAAGA,EAAIH,EAAGG,IACnBP,EAAQY,KAAM,GAIf,IADAT,EAAKU,EAAYf,GAAK,GAChBS,EAAIH,EAAE,EAAGG,GAAK,EAAGA,IAEtB,MADAC,EAAIH,EAAID,EAAIG,GACH,GAAT,CAMA,GAFAD,EAAIJ,EAAIM,GAEK,KADbP,EAAMF,EAAOQ,KACKN,EAAMK,EACvB,MAAM,IAAIK,MAAOG,EAAQ,8PAA+PC,EAAMb,GAAKc,KAAM,MAAQD,EAAMhB,GAAQiB,KAAM,MAAQT,IAE9U,GAAKD,IAAML,EACVD,EAASO,GAAMJ,EAAIK,OACb,IAAW,IAANF,EAKX,MAAM,IAAIK,MAAOG,EAAQ,2IAA4IC,EAAMb,GAAKc,KAAM,MAAQD,EAAMhB,GAAQiB,KAAM,MAAQT,IAH1NP,EAASO,GAAM,CAIf,CAdA,CAgBF,OAAOU,EAASC,EAAUpB,GAAOqB,EAASrB,GAAOiB,EAAMhB,GAASC,EAASoB,EAAWtB,GAAOuB,EAAUvB,GACtG"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 421366d..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 92530f40b5a0fb42a126501a253ee45b7683879d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Feb 2024 13:48:50 +0000 Subject: [PATCH 37/91] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 228 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 49 +- SECURITY.md | 5 - benchmark/benchmark.js | 161 - 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 | 65 - docs/types/test.ts | 94 - examples/index.js | 49 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 68 - lib/main.js | 143 - package.json | 67 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 511 -- 44 files changed, 6205 insertions(+), 4569 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 (96%) 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 bfeb23d..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-02-01T05:54:23.273Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 6c59584..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-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 7ab66d5..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-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 c175b42..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: '28 4 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index e1e3539..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -177,7 +168,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]. @@ -240,11 +231,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-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 d0243ca..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,161 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 broadcastArray = 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 = broadcastArray( 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', 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 = broadcastArray( 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', 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 = broadcastArray( 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(); -}); diff --git a/benchmark/benchmark.ndims.js b/benchmark/benchmark.ndims.js deleted file mode 100644 index 9530251..0000000 --- a/benchmark/benchmark.ndims.js +++ /dev/null @@ -1,110 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 broadcastArray = 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 = broadcastArray( 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 f51adca..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-array" -%% click B href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-array -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-array/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-array/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-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 a9d3107..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import broadcastArray from '../docs/types/index'; -export = broadcastArray; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index e7736e3..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var m=function(a,r){return function(){return r||a((r={exports:{}}).exports,r),r.exports}};var c=m(function(x,f){ -var t=require('@stdlib/array-base-copy-indexed/dist'),g=require('@stdlib/ndarray-base-ctor/dist'),l=require('@stdlib/ndarray-base-shape/dist'),y=require('@stdlib/ndarray-base-strides/dist'),q=require('@stdlib/ndarray-base-offset/dist'),b=require('@stdlib/ndarray-base-order/dist'),w=require('@stdlib/ndarray-base-dtype/dist'),D=require('@stdlib/ndarray-base-data-buffer/dist'),p=require('@stdlib/error-tools-fmtprodmsg/dist');function j(a,r){var i,o,s,v,n,u,d,e,h;if(n=r.length,s=l(a,!1),u=s.length,n=0;e--)if(h=u-n+e,!(h<0)){if(d=s[h],o=r[e],o!==0&&o\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction broadcastArray( arr, shape ) {\n\tvar strides;\n\tvar dim;\n\tvar sh;\n\tvar st;\n\tvar N;\n\tvar M;\n\tvar d;\n\tvar i;\n\tvar j;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\tM = sh.length;\n\tif ( N < M ) {\n\t\tthrow new Error( 'invalid argument. Cannot broadcast an array to a shape having fewer dimensions. Arrays can only be broadcasted to shapes having the same or more dimensions.' );\n\t}\n\t// Initialize a strides array...\n\tstrides = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tstrides.push( 0 );\n\t}\n\t// Determine the output array strides...\n\tst = getStrides( arr, false );\n\tfor ( i = N-1; i >= 0; i-- ) {\n\t\tj = M - N + i;\n\t\tif ( j < 0 ) {\n\t\t\t// Prepended singleton dimension; stride is zero...\n\t\t\tcontinue;\n\t\t}\n\t\td = sh[ j ];\n\t\tdim = shape[ i ];\n\t\tif ( dim !== 0 && dim < d ) {\n\t\t\tthrow new Error( format( 'invalid argument. Input array cannot be broadcast to the specified shape, as the specified shape has a dimension whose size is less than the size of the corresponding dimension in the input array. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t\tif ( d === dim ) {\n\t\t\tstrides[ i ] = st[ j ];\n\t\t} else if ( d === 1 ) {\n\t\t\t// In order to broadcast dimensions, we set the stride for that dimension to zero...\n\t\t\tstrides[ i ] = 0;\n\t\t} else {\n\t\t\t// At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when \"tiling\" an array; e.g., `dim=4` and `d=2`)...\n\t\t\tthrow new Error( format( 'invalid argument. Input array and the specified shape are broadcast incompatible. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t}\n\treturn ndarray( getDType( arr ), getData( arr ), copy( shape ), strides, getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nmodule.exports = broadcastArray;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast an ndarray to a specified shape.\n*\n* @module @stdlib/ndarray-base-broadcast-array\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var broadcastArray = require( '@stdlib/ndarray-base-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 = broadcastArray( 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,EAAO,QAAS,iCAAkC,EAClDC,EAAU,QAAS,2BAA4B,EAC/CC,EAAW,QAAS,4BAA6B,EACjDC,EAAa,QAAQ,8BAA+B,EACpDC,EAAY,QAAS,6BAA8B,EACnDC,EAAW,QAAS,4BAA6B,EACjDC,EAAW,QAAS,4BAA6B,EACjDC,EAAU,QAAS,kCAAmC,EACtDC,EAAS,QAAS,uBAAwB,EA6D9C,SAASC,EAAgBC,EAAKC,EAAQ,CACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACA,EACAC,EACAC,EAKJ,GAHAH,EAAIL,EAAM,OACVG,EAAKZ,EAAUQ,EAAK,EAAM,EAC1BO,EAAIH,EAAG,OACFE,EAAIC,EACR,MAAM,IAAI,MAAO,8JAA+J,EAIjL,IADAL,EAAU,CAAC,EACLM,EAAI,EAAGA,EAAIF,EAAGE,IACnBN,EAAQ,KAAM,CAAE,EAIjB,IADAG,EAAKZ,EAAYO,EAAK,EAAM,EACtBQ,EAAIF,EAAE,EAAGE,GAAK,EAAGA,IAEtB,GADAC,EAAIF,EAAID,EAAIE,EACP,EAAAC,EAAI,GAMT,IAFA,EAAIL,EAAIK,CAAE,EACVN,EAAMF,EAAOO,CAAE,EACVL,IAAQ,GAAKA,EAAM,EACvB,MAAM,IAAI,MAAOL,EAAQ,8PAA+PR,EAAMc,CAAG,EAAE,KAAM,IAAK,EAAGd,EAAMW,CAAM,EAAE,KAAM,IAAK,EAAGO,CAAE,CAAE,EAElV,GAAK,IAAML,EACVD,EAASM,CAAE,EAAIH,EAAII,CAAE,UACV,IAAM,EAEjBP,EAASM,CAAE,EAAI,MAGf,OAAM,IAAI,MAAOV,EAAQ,2IAA4IR,EAAMc,CAAG,EAAE,KAAM,IAAK,EAAGd,EAAMW,CAAM,EAAE,KAAM,IAAK,EAAGO,CAAE,CAAE,EAGhO,OAAOjB,EAASK,EAAUI,CAAI,EAAGH,EAASG,CAAI,EAAGV,EAAMW,CAAM,EAAGC,EAASR,EAAWM,CAAI,EAAGL,EAAUK,CAAI,CAAE,CAC5G,CAKAX,EAAO,QAAUU,IChFjB,IAAIW,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "copy", "ndarray", "getShape", "getStrides", "getOffset", "getOrder", "getDType", "getData", "format", "broadcastArray", "arr", "shape", "strides", "dim", "sh", "st", "N", "M", "i", "j", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index db0f44c..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,65 +0,0 @@ - -{{alias}}( arr, shape ) - Broadcasts an ndarray to a specified shape. - - The 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. - - The returned array is a "base" ndarray, and, thus, the returned array 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. - - The function always returns a new ndarray instance even if the input ndarray - shape and the desired shape are the same. - - 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 4041dc7..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,94 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 broadcastArray = 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(); - - broadcastArray( x, [ 2, 2, 2 ] ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is not provided a first argument which is an ndarray... -{ - broadcastArray( '5', [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( 5, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( true, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( false, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( null, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( {}, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( [ '5' ], [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( ( 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(); - - broadcastArray( x, '5' ); // $ExpectError - broadcastArray( x, 5 ); // $ExpectError - broadcastArray( x, true ); // $ExpectError - broadcastArray( x, false ); // $ExpectError - broadcastArray( x, null ); // $ExpectError - broadcastArray( x, {} ); // $ExpectError - broadcastArray( x, [ '5' ] ); // $ExpectError - broadcastArray( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - - broadcastArray(); // $ExpectError - broadcastArray( x ); // $ExpectError - broadcastArray( x, [ 1, 2, 3 ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index f0dc7b6..0000000 --- a/examples/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 broadcastArray = require( './../lib' ); - -// Create a 2x2 array: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -// returns - -// Broadcast the array to 3x2x2: -var y = broadcastArray( 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 sub; -var v; -var i; -for ( i = 0; i < N; i++ ) { - v = y.iget( i ); - sub = ind2sub( sh, i ); - console.log( 'Y[%s] = %d', sub.join( ', ' ), v ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index 672e358..89664bc 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..db51810 --- /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 s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy-indexed@v0.1.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function m(m,h){var p,j,f,l,b,v,c,g,y;if((b=h.length)<(v=(f=r(m,!1)).length))throw new Error("invalid argument. Cannot broadcast an array to a shape having fewer dimensions. Arrays can only be broadcasted to shapes having the same or more dimensions.");for(p=[],g=0;g=0;g--)if(!((y=v-b+g)<0)){if(c=f[y],0!==(j=h[g])&&j\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction broadcastArray( arr, shape ) {\n\tvar strides;\n\tvar dim;\n\tvar sh;\n\tvar st;\n\tvar N;\n\tvar M;\n\tvar d;\n\tvar i;\n\tvar j;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\tM = sh.length;\n\tif ( N < M ) {\n\t\tthrow new Error( 'invalid argument. Cannot broadcast an array to a shape having fewer dimensions. Arrays can only be broadcasted to shapes having the same or more dimensions.' );\n\t}\n\t// Initialize a strides array...\n\tstrides = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tstrides.push( 0 );\n\t}\n\t// Determine the output array strides...\n\tst = getStrides( arr, false );\n\tfor ( i = N-1; i >= 0; i-- ) {\n\t\tj = M - N + i;\n\t\tif ( j < 0 ) {\n\t\t\t// Prepended singleton dimension; stride is zero...\n\t\t\tcontinue;\n\t\t}\n\t\td = sh[ j ];\n\t\tdim = shape[ i ];\n\t\tif ( dim !== 0 && dim < d ) {\n\t\t\tthrow new Error( format( 'invalid argument. Input array cannot be broadcast to the specified shape, as the specified shape has a dimension whose size is less than the size of the corresponding dimension in the input array. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t\tif ( d === dim ) {\n\t\t\tstrides[ i ] = st[ j ];\n\t\t} else if ( d === 1 ) {\n\t\t\t// In order to broadcast dimensions, we set the stride for that dimension to zero...\n\t\t\tstrides[ i ] = 0;\n\t\t} else {\n\t\t\t// At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when \"tiling\" an array; e.g., `dim=4` and `d=2`)...\n\t\t\tthrow new Error( format( 'invalid argument. Input array and the specified shape are broadcast incompatible. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t}\n\treturn ndarray( getDType( arr ), getData( arr ), copy( shape ), strides, getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nexport default broadcastArray;\n"],"names":["broadcastArray","arr","shape","strides","dim","sh","st","N","M","d","i","j","length","getShape","Error","push","getStrides","format","copy","join","ndarray","getDType","getData","getOffset","getOrder"],"mappings":";;60BA2FA,SAASA,EAAgBC,EAAKC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAJ,EAAIL,EAAMU,SAEVJ,GADAH,EAAKQ,EAAUZ,GAAK,IACbW,QAEN,MAAM,IAAIE,MAAO,gKAIlB,IADAX,EAAU,GACJO,EAAI,EAAGA,EAAIH,EAAGG,IACnBP,EAAQY,KAAM,GAIf,IADAT,EAAKU,EAAYf,GAAK,GAChBS,EAAIH,EAAE,EAAGG,GAAK,EAAGA,IAEtB,MADAC,EAAIH,EAAID,EAAIG,GACH,GAAT,CAMA,GAFAD,EAAIJ,EAAIM,GAEK,KADbP,EAAMF,EAAOQ,KACKN,EAAMK,EACvB,MAAM,IAAIK,MAAOG,EAAQ,8PAA+PC,EAAMb,GAAKc,KAAM,MAAQD,EAAMhB,GAAQiB,KAAM,MAAQT,IAE9U,GAAKD,IAAML,EACVD,EAASO,GAAMJ,EAAIK,OACb,IAAW,IAANF,EAKX,MAAM,IAAIK,MAAOG,EAAQ,2IAA4IC,EAAMb,GAAKc,KAAM,MAAQD,EAAMhB,GAAQiB,KAAM,MAAQT,IAH1NP,EAASO,GAAM,CAIf,CAdA,CAgBF,OAAOU,EAASC,EAAUpB,GAAOqB,EAASrB,GAAOiB,EAAMhB,GAASC,EAASoB,EAAWtB,GAAOuB,EAAUvB,GACtG"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index b6aaa86..0000000 --- a/lib/index.js +++ /dev/null @@ -1,68 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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. -* -* @module @stdlib/ndarray-base-broadcast-array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var broadcastArray = require( '@stdlib/ndarray-base-broadcast-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = broadcastArray( 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 20e9b81..0000000 --- a/lib/main.js +++ /dev/null @@ -1,143 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var copy = require( '@stdlib/array-base-copy-indexed' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require('@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var format = require( '@stdlib/string-format' ); - - -// MAIN // - -/** -* Broadcasts an ndarray to a specified shape. -* -* ## Notes -* -* - The 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. -* -* @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 = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] ); -* // throws -*/ -function broadcastArray( arr, shape ) { - var strides; - var dim; - var sh; - var st; - var N; - var M; - var d; - var i; - var j; - - N = shape.length; - sh = getShape( arr, false ); - M = sh.length; - if ( N < M ) { - throw new Error( 'invalid argument. Cannot broadcast an array to a shape having fewer dimensions. Arrays can only be broadcasted to shapes having the same or more dimensions.' ); - } - // Initialize a strides array... - strides = []; - for ( i = 0; i < N; i++ ) { - strides.push( 0 ); - } - // Determine the output array strides... - st = getStrides( arr, false ); - for ( i = N-1; i >= 0; i-- ) { - j = M - N + i; - if ( j < 0 ) { - // Prepended singleton dimension; stride is zero... - continue; - } - d = sh[ j ]; - dim = shape[ i ]; - if ( dim !== 0 && dim < d ) { - throw new Error( format( 'invalid argument. Input array cannot be broadcast to the specified shape, as the specified shape has a dimension whose size is less than the size of the corresponding dimension in the input array. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); - } - if ( d === dim ) { - strides[ i ] = st[ j ]; - } else if ( d === 1 ) { - // In order to broadcast dimensions, we set the stride for that dimension to zero... - strides[ i ] = 0; - } else { - // At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when "tiling" an array; e.g., `dim=4` and `d=2`)... - throw new Error( format( 'invalid argument. Input array and the specified shape are broadcast incompatible. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); - } - } - return ndarray( getDType( arr ), getData( arr ), copy( shape ), strides, getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len -} - - -// EXPORTS // - -module.exports = broadcastArray; diff --git a/package.json b/package.json index e8dae63..a421f20 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Broadcast an ndarray to a specified 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,45 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-copy-indexed": "^0.1.0", - "@stdlib/ndarray-base-ctor": "^0.1.0", - "@stdlib/ndarray-base-data-buffer": "^0.1.0", - "@stdlib/ndarray-base-dtype": "^0.1.0", - "@stdlib/ndarray-base-offset": "^0.1.0", - "@stdlib/ndarray-base-order": "^0.1.0", - "@stdlib/ndarray-base-shape": "^0.1.0", - "@stdlib/ndarray-base-strides": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.2.0" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.1.1", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/ndarray-array": "^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", @@ -91,7 +29,6 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..9de6313 --- /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 97decdb..0000000 --- a/test/test.js +++ /dev/null @@ -1,511 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 broadcastArray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastArray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a desired shape which has fewer dimensions than 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() { - broadcastArray( 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() { - broadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape and an input array shape 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() { - broadcastArray( x, value ); - }; - } -}); - -tape( 'the function returns a "base" ndarray instance', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = broadcastArray( 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 = broadcastArray( 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.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, 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 = broadcastArray( x, expected ); - - actual = y.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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 e19ba536803b12754eb06e0eaabcd025f2f42f18 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 14 Feb 2024 23:57:27 +0000 Subject: [PATCH 38/91] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 367247c..bbf1951 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "@stdlib/ndarray-base-order": "^0.2.0", "@stdlib/ndarray-base-shape": "^0.2.0", "@stdlib/ndarray-base-strides": "^0.2.0", - "@stdlib/string-format": "^0.2.0", + "@stdlib/error-tools-fmtprodmsg": "^0.2.0", "@stdlib/types": "^0.3.1" }, "devDependencies": { From c1cd15bbcbbf33e625dacc6db4281288654d18de Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 02:49:35 +0000 Subject: [PATCH 39/91] Remove files --- index.d.ts | 80 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6262 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 89664bc..0000000 --- a/index.d.ts +++ /dev/null @@ -1,80 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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. -* -* ## Notes -* -* - The function throws an error if a provided ndarray is incompatible with a provided shape. -* - The 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. -* - The returned array is a "base" ndarray, and, thus, the returned array 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 always returns a new ndarray instance even if the input ndarray shape and the desired shape are the same. -* -* @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 -* @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 = broadcastArray( 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 broadcastArray( arr: ndarray, shape: ArrayLike ): ndarray; - - -// EXPORTS // - -export = broadcastArray; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index db51810..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 s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy-indexed@v0.1.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function m(m,h){var p,j,f,l,b,v,c,g,y;if((b=h.length)<(v=(f=r(m,!1)).length))throw new Error("invalid argument. Cannot broadcast an array to a shape having fewer dimensions. Arrays can only be broadcasted to shapes having the same or more dimensions.");for(p=[],g=0;g=0;g--)if(!((y=v-b+g)<0)){if(c=f[y],0!==(j=h[g])&&j\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction broadcastArray( arr, shape ) {\n\tvar strides;\n\tvar dim;\n\tvar sh;\n\tvar st;\n\tvar N;\n\tvar M;\n\tvar d;\n\tvar i;\n\tvar j;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\tM = sh.length;\n\tif ( N < M ) {\n\t\tthrow new Error( 'invalid argument. Cannot broadcast an array to a shape having fewer dimensions. Arrays can only be broadcasted to shapes having the same or more dimensions.' );\n\t}\n\t// Initialize a strides array...\n\tstrides = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tstrides.push( 0 );\n\t}\n\t// Determine the output array strides...\n\tst = getStrides( arr, false );\n\tfor ( i = N-1; i >= 0; i-- ) {\n\t\tj = M - N + i;\n\t\tif ( j < 0 ) {\n\t\t\t// Prepended singleton dimension; stride is zero...\n\t\t\tcontinue;\n\t\t}\n\t\td = sh[ j ];\n\t\tdim = shape[ i ];\n\t\tif ( dim !== 0 && dim < d ) {\n\t\t\tthrow new Error( format( 'invalid argument. Input array cannot be broadcast to the specified shape, as the specified shape has a dimension whose size is less than the size of the corresponding dimension in the input array. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t\tif ( d === dim ) {\n\t\t\tstrides[ i ] = st[ j ];\n\t\t} else if ( d === 1 ) {\n\t\t\t// In order to broadcast dimensions, we set the stride for that dimension to zero...\n\t\t\tstrides[ i ] = 0;\n\t\t} else {\n\t\t\t// At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when \"tiling\" an array; e.g., `dim=4` and `d=2`)...\n\t\t\tthrow new Error( format( 'invalid argument. Input array and the specified shape are broadcast incompatible. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t}\n\treturn ndarray( getDType( arr ), getData( arr ), copy( shape ), strides, getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nexport default broadcastArray;\n"],"names":["broadcastArray","arr","shape","strides","dim","sh","st","N","M","d","i","j","length","getShape","Error","push","getStrides","format","copy","join","ndarray","getDType","getData","getOffset","getOrder"],"mappings":";;60BA2FA,SAASA,EAAgBC,EAAKC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAJ,EAAIL,EAAMU,SAEVJ,GADAH,EAAKQ,EAAUZ,GAAK,IACbW,QAEN,MAAM,IAAIE,MAAO,gKAIlB,IADAX,EAAU,GACJO,EAAI,EAAGA,EAAIH,EAAGG,IACnBP,EAAQY,KAAM,GAIf,IADAT,EAAKU,EAAYf,GAAK,GAChBS,EAAIH,EAAE,EAAGG,GAAK,EAAGA,IAEtB,MADAC,EAAIH,EAAID,EAAIG,GACH,GAAT,CAMA,GAFAD,EAAIJ,EAAIM,GAEK,KADbP,EAAMF,EAAOQ,KACKN,EAAMK,EACvB,MAAM,IAAIK,MAAOG,EAAQ,8PAA+PC,EAAMb,GAAKc,KAAM,MAAQD,EAAMhB,GAAQiB,KAAM,MAAQT,IAE9U,GAAKD,IAAML,EACVD,EAASO,GAAMJ,EAAIK,OACb,IAAW,IAANF,EAKX,MAAM,IAAIK,MAAOG,EAAQ,2IAA4IC,EAAMb,GAAKc,KAAM,MAAQD,EAAMhB,GAAQiB,KAAM,MAAQT,IAH1NP,EAASO,GAAM,CAIf,CAdA,CAgBF,OAAOU,EAASC,EAAUpB,GAAOqB,EAASrB,GAAOiB,EAAMhB,GAASC,EAASoB,EAAWtB,GAAOuB,EAAUvB,GACtG"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 9de6313..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From ad9b2d1009644b34406a33663d5a13e9356616cf Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 02:50:15 +0000 Subject: [PATCH 40/91] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 132 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 228 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 49 +- SECURITY.md | 5 - benchmark/benchmark.js | 161 - 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 | 65 - docs/types/test.ts | 94 - examples/index.js | 49 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 68 - lib/main.js | 143 - package.json | 67 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 511 -- 43 files changed, 6205 insertions(+), 4572 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 (96%) 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 6c59584..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-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 7ab66d5..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-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 14afc93..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: '28 4 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 9106b5d..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -177,7 +168,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]. @@ -240,11 +231,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-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 d0243ca..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,161 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 broadcastArray = 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 = broadcastArray( 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', 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 = broadcastArray( 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', 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 = broadcastArray( 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(); -}); diff --git a/benchmark/benchmark.ndims.js b/benchmark/benchmark.ndims.js deleted file mode 100644 index 9530251..0000000 --- a/benchmark/benchmark.ndims.js +++ /dev/null @@ -1,110 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 broadcastArray = 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 = broadcastArray( 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 f51adca..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-array" -%% click B href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-array -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-array/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-array/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-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 a9d3107..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import broadcastArray from '../docs/types/index'; -export = broadcastArray; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index e7736e3..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var m=function(a,r){return function(){return r||a((r={exports:{}}).exports,r),r.exports}};var c=m(function(x,f){ -var t=require('@stdlib/array-base-copy-indexed/dist'),g=require('@stdlib/ndarray-base-ctor/dist'),l=require('@stdlib/ndarray-base-shape/dist'),y=require('@stdlib/ndarray-base-strides/dist'),q=require('@stdlib/ndarray-base-offset/dist'),b=require('@stdlib/ndarray-base-order/dist'),w=require('@stdlib/ndarray-base-dtype/dist'),D=require('@stdlib/ndarray-base-data-buffer/dist'),p=require('@stdlib/error-tools-fmtprodmsg/dist');function j(a,r){var i,o,s,v,n,u,d,e,h;if(n=r.length,s=l(a,!1),u=s.length,n=0;e--)if(h=u-n+e,!(h<0)){if(d=s[h],o=r[e],o!==0&&o\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction broadcastArray( arr, shape ) {\n\tvar strides;\n\tvar dim;\n\tvar sh;\n\tvar st;\n\tvar N;\n\tvar M;\n\tvar d;\n\tvar i;\n\tvar j;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\tM = sh.length;\n\tif ( N < M ) {\n\t\tthrow new Error( 'invalid argument. Cannot broadcast an array to a shape having fewer dimensions. Arrays can only be broadcasted to shapes having the same or more dimensions.' );\n\t}\n\t// Initialize a strides array...\n\tstrides = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tstrides.push( 0 );\n\t}\n\t// Determine the output array strides...\n\tst = getStrides( arr, false );\n\tfor ( i = N-1; i >= 0; i-- ) {\n\t\tj = M - N + i;\n\t\tif ( j < 0 ) {\n\t\t\t// Prepended singleton dimension; stride is zero...\n\t\t\tcontinue;\n\t\t}\n\t\td = sh[ j ];\n\t\tdim = shape[ i ];\n\t\tif ( dim !== 0 && dim < d ) {\n\t\t\tthrow new Error( format( 'invalid argument. Input array cannot be broadcast to the specified shape, as the specified shape has a dimension whose size is less than the size of the corresponding dimension in the input array. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t\tif ( d === dim ) {\n\t\t\tstrides[ i ] = st[ j ];\n\t\t} else if ( d === 1 ) {\n\t\t\t// In order to broadcast dimensions, we set the stride for that dimension to zero...\n\t\t\tstrides[ i ] = 0;\n\t\t} else {\n\t\t\t// At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when \"tiling\" an array; e.g., `dim=4` and `d=2`)...\n\t\t\tthrow new Error( format( 'invalid argument. Input array and the specified shape are broadcast incompatible. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t}\n\treturn ndarray( getDType( arr ), getData( arr ), copy( shape ), strides, getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nmodule.exports = broadcastArray;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast an ndarray to a specified shape.\n*\n* @module @stdlib/ndarray-base-broadcast-array\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var broadcastArray = require( '@stdlib/ndarray-base-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 = broadcastArray( 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,EAAO,QAAS,iCAAkC,EAClDC,EAAU,QAAS,2BAA4B,EAC/CC,EAAW,QAAS,4BAA6B,EACjDC,EAAa,QAAQ,8BAA+B,EACpDC,EAAY,QAAS,6BAA8B,EACnDC,EAAW,QAAS,4BAA6B,EACjDC,EAAW,QAAS,4BAA6B,EACjDC,EAAU,QAAS,kCAAmC,EACtDC,EAAS,QAAS,uBAAwB,EA6D9C,SAASC,EAAgBC,EAAKC,EAAQ,CACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACA,EACAC,EACAC,EAKJ,GAHAH,EAAIL,EAAM,OACVG,EAAKZ,EAAUQ,EAAK,EAAM,EAC1BO,EAAIH,EAAG,OACFE,EAAIC,EACR,MAAM,IAAI,MAAO,8JAA+J,EAIjL,IADAL,EAAU,CAAC,EACLM,EAAI,EAAGA,EAAIF,EAAGE,IACnBN,EAAQ,KAAM,CAAE,EAIjB,IADAG,EAAKZ,EAAYO,EAAK,EAAM,EACtBQ,EAAIF,EAAE,EAAGE,GAAK,EAAGA,IAEtB,GADAC,EAAIF,EAAID,EAAIE,EACP,EAAAC,EAAI,GAMT,IAFA,EAAIL,EAAIK,CAAE,EACVN,EAAMF,EAAOO,CAAE,EACVL,IAAQ,GAAKA,EAAM,EACvB,MAAM,IAAI,MAAOL,EAAQ,8PAA+PR,EAAMc,CAAG,EAAE,KAAM,IAAK,EAAGd,EAAMW,CAAM,EAAE,KAAM,IAAK,EAAGO,CAAE,CAAE,EAElV,GAAK,IAAML,EACVD,EAASM,CAAE,EAAIH,EAAII,CAAE,UACV,IAAM,EAEjBP,EAASM,CAAE,EAAI,MAGf,OAAM,IAAI,MAAOV,EAAQ,2IAA4IR,EAAMc,CAAG,EAAE,KAAM,IAAK,EAAGd,EAAMW,CAAM,EAAE,KAAM,IAAK,EAAGO,CAAE,CAAE,EAGhO,OAAOjB,EAASK,EAAUI,CAAI,EAAGH,EAASG,CAAI,EAAGV,EAAMW,CAAM,EAAGC,EAASR,EAAWM,CAAI,EAAGL,EAAUK,CAAI,CAAE,CAC5G,CAKAX,EAAO,QAAUU,IChFjB,IAAIW,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "copy", "ndarray", "getShape", "getStrides", "getOffset", "getOrder", "getDType", "getData", "format", "broadcastArray", "arr", "shape", "strides", "dim", "sh", "st", "N", "M", "i", "j", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index db0f44c..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,65 +0,0 @@ - -{{alias}}( arr, shape ) - Broadcasts an ndarray to a specified shape. - - The 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. - - The returned array is a "base" ndarray, and, thus, the returned array 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. - - The function always returns a new ndarray instance even if the input ndarray - shape and the desired shape are the same. - - 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 4041dc7..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,94 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 broadcastArray = 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(); - - broadcastArray( x, [ 2, 2, 2 ] ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is not provided a first argument which is an ndarray... -{ - broadcastArray( '5', [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( 5, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( true, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( false, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( null, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( {}, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( [ '5' ], [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( ( 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(); - - broadcastArray( x, '5' ); // $ExpectError - broadcastArray( x, 5 ); // $ExpectError - broadcastArray( x, true ); // $ExpectError - broadcastArray( x, false ); // $ExpectError - broadcastArray( x, null ); // $ExpectError - broadcastArray( x, {} ); // $ExpectError - broadcastArray( x, [ '5' ] ); // $ExpectError - broadcastArray( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - - broadcastArray(); // $ExpectError - broadcastArray( x ); // $ExpectError - broadcastArray( x, [ 1, 2, 3 ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index f0dc7b6..0000000 --- a/examples/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 broadcastArray = require( './../lib' ); - -// Create a 2x2 array: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -// returns - -// Broadcast the array to 3x2x2: -var y = broadcastArray( 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 sub; -var v; -var i; -for ( i = 0; i < N; i++ ) { - v = y.iget( i ); - sub = ind2sub( sh, i ); - console.log( 'Y[%s] = %d', sub.join( ', ' ), v ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index 672e358..89664bc 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..6b49c96 --- /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 s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy-indexed@v0.1.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.2.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.2.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function m(m,h){var p,j,f,l,b,v,c,g,y;if((b=h.length)<(v=(f=r(m,!1)).length))throw new Error("invalid argument. Cannot broadcast an array to a shape having fewer dimensions. Arrays can only be broadcasted to shapes having the same or more dimensions.");for(p=[],g=0;g=0;g--)if(!((y=v-b+g)<0)){if(c=f[y],0!==(j=h[g])&&j\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction broadcastArray( arr, shape ) {\n\tvar strides;\n\tvar dim;\n\tvar sh;\n\tvar st;\n\tvar N;\n\tvar M;\n\tvar d;\n\tvar i;\n\tvar j;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\tM = sh.length;\n\tif ( N < M ) {\n\t\tthrow new Error( 'invalid argument. Cannot broadcast an array to a shape having fewer dimensions. Arrays can only be broadcasted to shapes having the same or more dimensions.' );\n\t}\n\t// Initialize a strides array...\n\tstrides = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tstrides.push( 0 );\n\t}\n\t// Determine the output array strides...\n\tst = getStrides( arr, false );\n\tfor ( i = N-1; i >= 0; i-- ) {\n\t\tj = M - N + i;\n\t\tif ( j < 0 ) {\n\t\t\t// Prepended singleton dimension; stride is zero...\n\t\t\tcontinue;\n\t\t}\n\t\td = sh[ j ];\n\t\tdim = shape[ i ];\n\t\tif ( dim !== 0 && dim < d ) {\n\t\t\tthrow new Error( format( 'invalid argument. Input array cannot be broadcast to the specified shape, as the specified shape has a dimension whose size is less than the size of the corresponding dimension in the input array. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t\tif ( d === dim ) {\n\t\t\tstrides[ i ] = st[ j ];\n\t\t} else if ( d === 1 ) {\n\t\t\t// In order to broadcast dimensions, we set the stride for that dimension to zero...\n\t\t\tstrides[ i ] = 0;\n\t\t} else {\n\t\t\t// At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when \"tiling\" an array; e.g., `dim=4` and `d=2`)...\n\t\t\tthrow new Error( format( 'invalid argument. Input array and the specified shape are broadcast incompatible. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t}\n\treturn ndarray( getDType( arr ), getData( arr ), copy( shape ), strides, getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nexport default broadcastArray;\n"],"names":["broadcastArray","arr","shape","strides","dim","sh","st","N","M","d","i","j","length","getShape","Error","push","getStrides","format","copy","join","ndarray","getDType","getData","getOffset","getOrder"],"mappings":";;60BA2FA,SAASA,EAAgBC,EAAKC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAJ,EAAIL,EAAMU,SAEVJ,GADAH,EAAKQ,EAAUZ,GAAK,IACbW,QAEN,MAAM,IAAIE,MAAO,gKAIlB,IADAX,EAAU,GACJO,EAAI,EAAGA,EAAIH,EAAGG,IACnBP,EAAQY,KAAM,GAIf,IADAT,EAAKU,EAAYf,GAAK,GAChBS,EAAIH,EAAE,EAAGG,GAAK,EAAGA,IAEtB,MADAC,EAAIH,EAAID,EAAIG,GACH,GAAT,CAMA,GAFAD,EAAIJ,EAAIM,GAEK,KADbP,EAAMF,EAAOQ,KACKN,EAAMK,EACvB,MAAM,IAAIK,MAAOG,EAAQ,8PAA+PC,EAAMb,GAAKc,KAAM,MAAQD,EAAMhB,GAAQiB,KAAM,MAAQT,IAE9U,GAAKD,IAAML,EACVD,EAASO,GAAMJ,EAAIK,OACb,IAAW,IAANF,EAKX,MAAM,IAAIK,MAAOG,EAAQ,2IAA4IC,EAAMb,GAAKc,KAAM,MAAQD,EAAMhB,GAAQiB,KAAM,MAAQT,IAH1NP,EAASO,GAAM,CAIf,CAdA,CAgBF,OAAOU,EAASC,EAAUpB,GAAOqB,EAASrB,GAAOiB,EAAMhB,GAASC,EAASoB,EAAWtB,GAAOuB,EAAUvB,GACtG"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index b6aaa86..0000000 --- a/lib/index.js +++ /dev/null @@ -1,68 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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. -* -* @module @stdlib/ndarray-base-broadcast-array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var broadcastArray = require( '@stdlib/ndarray-base-broadcast-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = broadcastArray( 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 20e9b81..0000000 --- a/lib/main.js +++ /dev/null @@ -1,143 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var copy = require( '@stdlib/array-base-copy-indexed' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require('@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var format = require( '@stdlib/string-format' ); - - -// MAIN // - -/** -* Broadcasts an ndarray to a specified shape. -* -* ## Notes -* -* - The 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. -* -* @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 = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] ); -* // throws -*/ -function broadcastArray( arr, shape ) { - var strides; - var dim; - var sh; - var st; - var N; - var M; - var d; - var i; - var j; - - N = shape.length; - sh = getShape( arr, false ); - M = sh.length; - if ( N < M ) { - throw new Error( 'invalid argument. Cannot broadcast an array to a shape having fewer dimensions. Arrays can only be broadcasted to shapes having the same or more dimensions.' ); - } - // Initialize a strides array... - strides = []; - for ( i = 0; i < N; i++ ) { - strides.push( 0 ); - } - // Determine the output array strides... - st = getStrides( arr, false ); - for ( i = N-1; i >= 0; i-- ) { - j = M - N + i; - if ( j < 0 ) { - // Prepended singleton dimension; stride is zero... - continue; - } - d = sh[ j ]; - dim = shape[ i ]; - if ( dim !== 0 && dim < d ) { - throw new Error( format( 'invalid argument. Input array cannot be broadcast to the specified shape, as the specified shape has a dimension whose size is less than the size of the corresponding dimension in the input array. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); - } - if ( d === dim ) { - strides[ i ] = st[ j ]; - } else if ( d === 1 ) { - // In order to broadcast dimensions, we set the stride for that dimension to zero... - strides[ i ] = 0; - } else { - // At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when "tiling" an array; e.g., `dim=4` and `d=2`)... - throw new Error( format( 'invalid argument. Input array and the specified shape are broadcast incompatible. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); - } - } - return ndarray( getDType( arr ), getData( arr ), copy( shape ), strides, getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len -} - - -// EXPORTS // - -module.exports = broadcastArray; diff --git a/package.json b/package.json index bbf1951..46230b8 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.0", "description": "Broadcast an ndarray to a specified 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,45 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-copy-indexed": "^0.2.0", - "@stdlib/ndarray-base-ctor": "^0.2.0", - "@stdlib/ndarray-base-data-buffer": "^0.2.0", - "@stdlib/ndarray-base-dtype": "^0.2.0", - "@stdlib/ndarray-base-offset": "^0.2.0", - "@stdlib/ndarray-base-order": "^0.2.0", - "@stdlib/ndarray-base-shape": "^0.2.0", - "@stdlib/ndarray-base-strides": "^0.2.0", - "@stdlib/error-tools-fmtprodmsg": "^0.2.0", - "@stdlib/types": "^0.3.1" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.2.0", - "@stdlib/assert-is-ndarray-like": "^0.2.0", - "@stdlib/ndarray-array": "^0.1.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", @@ -91,7 +29,6 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..cb8a861 --- /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 97decdb..0000000 --- a/test/test.js +++ /dev/null @@ -1,511 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 broadcastArray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastArray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a desired shape which has fewer dimensions than 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() { - broadcastArray( 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() { - broadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape and an input array shape 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() { - broadcastArray( x, value ); - }; - } -}); - -tape( 'the function returns a "base" ndarray instance', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = broadcastArray( 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 = broadcastArray( 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.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, 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 = broadcastArray( x, expected ); - - actual = y.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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 d5421d12c1d71353a6c8807107d96aad0aca26c8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 04:33:36 +0000 Subject: [PATCH 41/91] Update README.md for ESM bundle v0.2.0 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4384f37..c9944c0 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ limitations under the License. ## Usage ```javascript -import broadcastArray from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@esm/index.mjs'; +import broadcastArray from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@v0.2.0-esm/index.mjs'; ``` #### broadcastArray( arr, shape ) @@ -107,7 +107,7 @@ var y = broadcastArray( 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 broadcastArray from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@esm/index.mjs'; +import broadcastArray from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@v0.2.0-esm/index.mjs'; // Create a 2x2 array: var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); From 4fc513ba280eca72b43a5e93c2d2d0e04847b01f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 04:33:36 +0000 Subject: [PATCH 42/91] Auto-generated commit --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c9944c0..a94dbc5 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,11 @@ limitations under the License. ## Usage +```javascript +import broadcastArray from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-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-broadcast-array/tags). For example, + ```javascript import broadcastArray from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@v0.2.0-esm/index.mjs'; ``` @@ -107,7 +112,7 @@ var y = broadcastArray( 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 broadcastArray from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@v0.2.0-esm/index.mjs'; +import broadcastArray from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@esm/index.mjs'; // Create a 2x2 array: var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); From 54d663bc947cc9e1ddb9f549ae37da4b52c4f3a7 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 18:52:49 +0000 Subject: [PATCH 43/91] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index 20e9b81..3e61be9 100644 --- a/lib/main.js +++ b/lib/main.js @@ -28,7 +28,7 @@ var getOffset = require( '@stdlib/ndarray-base-offset' ); var getOrder = require( '@stdlib/ndarray-base-order' ); var getDType = require( '@stdlib/ndarray-base-dtype' ); var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -104,7 +104,7 @@ function broadcastArray( arr, shape ) { sh = getShape( arr, false ); M = sh.length; if ( N < M ) { - throw new Error( 'invalid argument. Cannot broadcast an array to a shape having fewer dimensions. Arrays can only be broadcasted to shapes having the same or more dimensions.' ); + throw new Error( format('0i50Z') ); } // Initialize a strides array... strides = []; @@ -122,7 +122,7 @@ function broadcastArray( arr, shape ) { d = sh[ j ]; dim = shape[ i ]; if ( dim !== 0 && dim < d ) { - throw new Error( format( 'invalid argument. Input array cannot be broadcast to the specified shape, as the specified shape has a dimension whose size is less than the size of the corresponding dimension in the input array. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); + throw new Error( format( '0i55F', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); } if ( d === dim ) { strides[ i ] = st[ j ]; @@ -131,7 +131,7 @@ function broadcastArray( arr, shape ) { strides[ i ] = 0; } else { // At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when "tiling" an array; e.g., `dim=4` and `d=2`)... - throw new Error( format( 'invalid argument. Input array and the specified shape are broadcast incompatible. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); + throw new Error( format( '0i55G', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); } } return ndarray( getDType( arr ), getData( arr ), copy( shape ), strides, getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len diff --git a/package.json b/package.json index 709ea15..79c6b13 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "@stdlib/ndarray-base-order": "^0.2.1", "@stdlib/ndarray-base-shape": "^0.2.1", "@stdlib/ndarray-base-strides": "^0.2.1", - "@stdlib/string-format": "^0.2.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1", "@stdlib/types": "^0.3.2", "@stdlib/error-tools-fmtprodmsg": "^0.2.1" }, From 12fd8afc1ae6878f4d536a995b0f1aca18890f0e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 19:08:23 +0000 Subject: [PATCH 44/91] Remove files --- index.d.ts | 80 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6262 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 89664bc..0000000 --- a/index.d.ts +++ /dev/null @@ -1,80 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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. -* -* ## Notes -* -* - The function throws an error if a provided ndarray is incompatible with a provided shape. -* - The 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. -* - The returned array is a "base" ndarray, and, thus, the returned array 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 always returns a new ndarray instance even if the input ndarray shape and the desired shape are the same. -* -* @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 -* @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 = broadcastArray( 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 broadcastArray( arr: ndarray, shape: ArrayLike ): ndarray; - - -// EXPORTS // - -export = broadcastArray; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 6b49c96..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 s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy-indexed@v0.1.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.2.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.2.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function m(m,h){var p,j,f,l,b,v,c,g,y;if((b=h.length)<(v=(f=r(m,!1)).length))throw new Error("invalid argument. Cannot broadcast an array to a shape having fewer dimensions. Arrays can only be broadcasted to shapes having the same or more dimensions.");for(p=[],g=0;g=0;g--)if(!((y=v-b+g)<0)){if(c=f[y],0!==(j=h[g])&&j\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction broadcastArray( arr, shape ) {\n\tvar strides;\n\tvar dim;\n\tvar sh;\n\tvar st;\n\tvar N;\n\tvar M;\n\tvar d;\n\tvar i;\n\tvar j;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\tM = sh.length;\n\tif ( N < M ) {\n\t\tthrow new Error( 'invalid argument. Cannot broadcast an array to a shape having fewer dimensions. Arrays can only be broadcasted to shapes having the same or more dimensions.' );\n\t}\n\t// Initialize a strides array...\n\tstrides = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tstrides.push( 0 );\n\t}\n\t// Determine the output array strides...\n\tst = getStrides( arr, false );\n\tfor ( i = N-1; i >= 0; i-- ) {\n\t\tj = M - N + i;\n\t\tif ( j < 0 ) {\n\t\t\t// Prepended singleton dimension; stride is zero...\n\t\t\tcontinue;\n\t\t}\n\t\td = sh[ j ];\n\t\tdim = shape[ i ];\n\t\tif ( dim !== 0 && dim < d ) {\n\t\t\tthrow new Error( format( 'invalid argument. Input array cannot be broadcast to the specified shape, as the specified shape has a dimension whose size is less than the size of the corresponding dimension in the input array. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t\tif ( d === dim ) {\n\t\t\tstrides[ i ] = st[ j ];\n\t\t} else if ( d === 1 ) {\n\t\t\t// In order to broadcast dimensions, we set the stride for that dimension to zero...\n\t\t\tstrides[ i ] = 0;\n\t\t} else {\n\t\t\t// At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when \"tiling\" an array; e.g., `dim=4` and `d=2`)...\n\t\t\tthrow new Error( format( 'invalid argument. Input array and the specified shape are broadcast incompatible. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t}\n\treturn ndarray( getDType( arr ), getData( arr ), copy( shape ), strides, getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nexport default broadcastArray;\n"],"names":["broadcastArray","arr","shape","strides","dim","sh","st","N","M","d","i","j","length","getShape","Error","push","getStrides","format","copy","join","ndarray","getDType","getData","getOffset","getOrder"],"mappings":";;60BA2FA,SAASA,EAAgBC,EAAKC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAJ,EAAIL,EAAMU,SAEVJ,GADAH,EAAKQ,EAAUZ,GAAK,IACbW,QAEN,MAAM,IAAIE,MAAO,gKAIlB,IADAX,EAAU,GACJO,EAAI,EAAGA,EAAIH,EAAGG,IACnBP,EAAQY,KAAM,GAIf,IADAT,EAAKU,EAAYf,GAAK,GAChBS,EAAIH,EAAE,EAAGG,GAAK,EAAGA,IAEtB,MADAC,EAAIH,EAAID,EAAIG,GACH,GAAT,CAMA,GAFAD,EAAIJ,EAAIM,GAEK,KADbP,EAAMF,EAAOQ,KACKN,EAAMK,EACvB,MAAM,IAAIK,MAAOG,EAAQ,8PAA+PC,EAAMb,GAAKc,KAAM,MAAQD,EAAMhB,GAAQiB,KAAM,MAAQT,IAE9U,GAAKD,IAAML,EACVD,EAASO,GAAMJ,EAAIK,OACb,IAAW,IAANF,EAKX,MAAM,IAAIK,MAAOG,EAAQ,2IAA4IC,EAAMb,GAAKc,KAAM,MAAQD,EAAMhB,GAAQiB,KAAM,MAAQT,IAH1NP,EAASO,GAAM,CAIf,CAdA,CAgBF,OAAOU,EAASC,EAAUpB,GAAOqB,EAASrB,GAAOiB,EAAMhB,GAASC,EAASoB,EAAWtB,GAAOuB,EAAUvB,GACtG"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index cb8a861..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 46d3da1bf73db35ef1a1a860ef29025d4d44f15d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 19:08:41 +0000 Subject: [PATCH 45/91] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 ---- .github/workflows/publish.yml | 249 -- .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 132 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 228 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 49 +- SECURITY.md | 5 - benchmark/benchmark.js | 161 - 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 | 65 - docs/types/test.ts | 94 - examples/index.js | 49 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 68 - lib/main.js | 143 - package.json | 68 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 511 --- 43 files changed, 4870 insertions(+), 4567 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 (96%) 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 6c59584..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-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 7ab66d5..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-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 e1434bb..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: '28 4 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 9106b5d..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -177,7 +168,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]. @@ -240,11 +231,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-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 d0243ca..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,161 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 broadcastArray = 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 = broadcastArray( 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', 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 = broadcastArray( 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', 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 = broadcastArray( 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(); -}); diff --git a/benchmark/benchmark.ndims.js b/benchmark/benchmark.ndims.js deleted file mode 100644 index 9530251..0000000 --- a/benchmark/benchmark.ndims.js +++ /dev/null @@ -1,110 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 broadcastArray = 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 = broadcastArray( 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 f51adca..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-array" -%% click B href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-array -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-array/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-array/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-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 a9d3107..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import broadcastArray from '../docs/types/index'; -export = broadcastArray; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index e7736e3..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var m=function(a,r){return function(){return r||a((r={exports:{}}).exports,r),r.exports}};var c=m(function(x,f){ -var t=require('@stdlib/array-base-copy-indexed/dist'),g=require('@stdlib/ndarray-base-ctor/dist'),l=require('@stdlib/ndarray-base-shape/dist'),y=require('@stdlib/ndarray-base-strides/dist'),q=require('@stdlib/ndarray-base-offset/dist'),b=require('@stdlib/ndarray-base-order/dist'),w=require('@stdlib/ndarray-base-dtype/dist'),D=require('@stdlib/ndarray-base-data-buffer/dist'),p=require('@stdlib/error-tools-fmtprodmsg/dist');function j(a,r){var i,o,s,v,n,u,d,e,h;if(n=r.length,s=l(a,!1),u=s.length,n=0;e--)if(h=u-n+e,!(h<0)){if(d=s[h],o=r[e],o!==0&&o\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction broadcastArray( arr, shape ) {\n\tvar strides;\n\tvar dim;\n\tvar sh;\n\tvar st;\n\tvar N;\n\tvar M;\n\tvar d;\n\tvar i;\n\tvar j;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\tM = sh.length;\n\tif ( N < M ) {\n\t\tthrow new Error( 'invalid argument. Cannot broadcast an array to a shape having fewer dimensions. Arrays can only be broadcasted to shapes having the same or more dimensions.' );\n\t}\n\t// Initialize a strides array...\n\tstrides = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tstrides.push( 0 );\n\t}\n\t// Determine the output array strides...\n\tst = getStrides( arr, false );\n\tfor ( i = N-1; i >= 0; i-- ) {\n\t\tj = M - N + i;\n\t\tif ( j < 0 ) {\n\t\t\t// Prepended singleton dimension; stride is zero...\n\t\t\tcontinue;\n\t\t}\n\t\td = sh[ j ];\n\t\tdim = shape[ i ];\n\t\tif ( dim !== 0 && dim < d ) {\n\t\t\tthrow new Error( format( 'invalid argument. Input array cannot be broadcast to the specified shape, as the specified shape has a dimension whose size is less than the size of the corresponding dimension in the input array. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t\tif ( d === dim ) {\n\t\t\tstrides[ i ] = st[ j ];\n\t\t} else if ( d === 1 ) {\n\t\t\t// In order to broadcast dimensions, we set the stride for that dimension to zero...\n\t\t\tstrides[ i ] = 0;\n\t\t} else {\n\t\t\t// At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when \"tiling\" an array; e.g., `dim=4` and `d=2`)...\n\t\t\tthrow new Error( format( 'invalid argument. Input array and the specified shape are broadcast incompatible. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t}\n\treturn ndarray( getDType( arr ), getData( arr ), copy( shape ), strides, getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nmodule.exports = broadcastArray;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast an ndarray to a specified shape.\n*\n* @module @stdlib/ndarray-base-broadcast-array\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var broadcastArray = require( '@stdlib/ndarray-base-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 = broadcastArray( 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,EAAO,QAAS,iCAAkC,EAClDC,EAAU,QAAS,2BAA4B,EAC/CC,EAAW,QAAS,4BAA6B,EACjDC,EAAa,QAAQ,8BAA+B,EACpDC,EAAY,QAAS,6BAA8B,EACnDC,EAAW,QAAS,4BAA6B,EACjDC,EAAW,QAAS,4BAA6B,EACjDC,EAAU,QAAS,kCAAmC,EACtDC,EAAS,QAAS,uBAAwB,EA6D9C,SAASC,EAAgBC,EAAKC,EAAQ,CACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACA,EACAC,EACAC,EAKJ,GAHAH,EAAIL,EAAM,OACVG,EAAKZ,EAAUQ,EAAK,EAAM,EAC1BO,EAAIH,EAAG,OACFE,EAAIC,EACR,MAAM,IAAI,MAAO,8JAA+J,EAIjL,IADAL,EAAU,CAAC,EACLM,EAAI,EAAGA,EAAIF,EAAGE,IACnBN,EAAQ,KAAM,CAAE,EAIjB,IADAG,EAAKZ,EAAYO,EAAK,EAAM,EACtBQ,EAAIF,EAAE,EAAGE,GAAK,EAAGA,IAEtB,GADAC,EAAIF,EAAID,EAAIE,EACP,EAAAC,EAAI,GAMT,IAFA,EAAIL,EAAIK,CAAE,EACVN,EAAMF,EAAOO,CAAE,EACVL,IAAQ,GAAKA,EAAM,EACvB,MAAM,IAAI,MAAOL,EAAQ,8PAA+PR,EAAMc,CAAG,EAAE,KAAM,IAAK,EAAGd,EAAMW,CAAM,EAAE,KAAM,IAAK,EAAGO,CAAE,CAAE,EAElV,GAAK,IAAML,EACVD,EAASM,CAAE,EAAIH,EAAII,CAAE,UACV,IAAM,EAEjBP,EAASM,CAAE,EAAI,MAGf,OAAM,IAAI,MAAOV,EAAQ,2IAA4IR,EAAMc,CAAG,EAAE,KAAM,IAAK,EAAGd,EAAMW,CAAM,EAAE,KAAM,IAAK,EAAGO,CAAE,CAAE,EAGhO,OAAOjB,EAASK,EAAUI,CAAI,EAAGH,EAASG,CAAI,EAAGV,EAAMW,CAAM,EAAGC,EAASR,EAAWM,CAAI,EAAGL,EAAUK,CAAI,CAAE,CAC5G,CAKAX,EAAO,QAAUU,IChFjB,IAAIW,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "copy", "ndarray", "getShape", "getStrides", "getOffset", "getOrder", "getDType", "getData", "format", "broadcastArray", "arr", "shape", "strides", "dim", "sh", "st", "N", "M", "i", "j", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index db0f44c..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,65 +0,0 @@ - -{{alias}}( arr, shape ) - Broadcasts an ndarray to a specified shape. - - The 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. - - The returned array is a "base" ndarray, and, thus, the returned array 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. - - The function always returns a new ndarray instance even if the input ndarray - shape and the desired shape are the same. - - 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 4041dc7..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,94 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 broadcastArray = 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(); - - broadcastArray( x, [ 2, 2, 2 ] ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is not provided a first argument which is an ndarray... -{ - broadcastArray( '5', [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( 5, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( true, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( false, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( null, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( {}, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( [ '5' ], [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( ( 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(); - - broadcastArray( x, '5' ); // $ExpectError - broadcastArray( x, 5 ); // $ExpectError - broadcastArray( x, true ); // $ExpectError - broadcastArray( x, false ); // $ExpectError - broadcastArray( x, null ); // $ExpectError - broadcastArray( x, {} ); // $ExpectError - broadcastArray( x, [ '5' ] ); // $ExpectError - broadcastArray( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - - broadcastArray(); // $ExpectError - broadcastArray( x ); // $ExpectError - broadcastArray( x, [ 1, 2, 3 ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index f0dc7b6..0000000 --- a/examples/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 broadcastArray = require( './../lib' ); - -// Create a 2x2 array: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -// returns - -// Broadcast the array to 3x2x2: -var y = broadcastArray( 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 sub; -var v; -var i; -for ( i = 0; i < N; i++ ) { - v = y.iget( i ); - sub = ind2sub( sh, i ); - console.log( 'Y[%s] = %d', sub.join( ', ' ), v ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index 672e358..89664bc 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..84f7fb9 --- /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 s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy-indexed@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function j(j,a){var h,p,f,l,v,b,c,g,x;if((v=a.length)<(b=(f=e(j,!1)).length))throw new Error(m("0i50Z"));for(h=[],g=0;g=0;g--)if(!((x=b-v+g)<0)){if(c=f[x],0!==(p=a[g])&&p\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction broadcastArray( arr, shape ) {\n\tvar strides;\n\tvar dim;\n\tvar sh;\n\tvar st;\n\tvar N;\n\tvar M;\n\tvar d;\n\tvar i;\n\tvar j;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\tM = sh.length;\n\tif ( N < M ) {\n\t\tthrow new Error( format('0i50Z') );\n\t}\n\t// Initialize a strides array...\n\tstrides = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tstrides.push( 0 );\n\t}\n\t// Determine the output array strides...\n\tst = getStrides( arr, false );\n\tfor ( i = N-1; i >= 0; i-- ) {\n\t\tj = M - N + i;\n\t\tif ( j < 0 ) {\n\t\t\t// Prepended singleton dimension; stride is zero...\n\t\t\tcontinue;\n\t\t}\n\t\td = sh[ j ];\n\t\tdim = shape[ i ];\n\t\tif ( dim !== 0 && dim < d ) {\n\t\t\tthrow new Error( format( '0i55F', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t\tif ( d === dim ) {\n\t\t\tstrides[ i ] = st[ j ];\n\t\t} else if ( d === 1 ) {\n\t\t\t// In order to broadcast dimensions, we set the stride for that dimension to zero...\n\t\t\tstrides[ i ] = 0;\n\t\t} else {\n\t\t\t// At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when \"tiling\" an array; e.g., `dim=4` and `d=2`)...\n\t\t\tthrow new Error( format( '0i55G', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t}\n\treturn ndarray( getDType( arr ), getData( arr ), copy( shape ), strides, getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nexport default broadcastArray;\n"],"names":["broadcastArray","arr","shape","strides","dim","sh","st","N","M","d","i","j","length","getShape","Error","format","push","getStrides","copy","join","ndarray","getDType","getData","getOffset","getOrder"],"mappings":";;s1BA2FA,SAASA,EAAgBC,EAAKC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAJ,EAAIL,EAAMU,SAEVJ,GADAH,EAAKQ,EAAUZ,GAAK,IACbW,QAEN,MAAM,IAAIE,MAAOC,EAAO,UAIzB,IADAZ,EAAU,GACJO,EAAI,EAAGA,EAAIH,EAAGG,IACnBP,EAAQa,KAAM,GAIf,IADAV,EAAKW,EAAYhB,GAAK,GAChBS,EAAIH,EAAE,EAAGG,GAAK,EAAGA,IAEtB,MADAC,EAAIH,EAAID,EAAIG,GACH,GAAT,CAMA,GAFAD,EAAIJ,EAAIM,GAEK,KADbP,EAAMF,EAAOQ,KACKN,EAAMK,EACvB,MAAM,IAAIK,MAAOC,EAAQ,QAASG,EAAMb,GAAKc,KAAM,MAAQD,EAAMhB,GAAQiB,KAAM,MAAQT,IAExF,GAAKD,IAAML,EACVD,EAASO,GAAMJ,EAAIK,OACb,IAAW,IAANF,EAKX,MAAM,IAAIK,MAAOC,EAAQ,QAASG,EAAMb,GAAKc,KAAM,MAAQD,EAAMhB,GAAQiB,KAAM,MAAQT,IAHvFP,EAASO,GAAM,CAIf,CAdA,CAgBF,OAAOU,EAASC,EAAUpB,GAAOqB,EAASrB,GAAOiB,EAAMhB,GAASC,EAASoB,EAAWtB,GAAOuB,EAAUvB,GACtG"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index b6aaa86..0000000 --- a/lib/index.js +++ /dev/null @@ -1,68 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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. -* -* @module @stdlib/ndarray-base-broadcast-array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var broadcastArray = require( '@stdlib/ndarray-base-broadcast-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = broadcastArray( 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 3e61be9..0000000 --- a/lib/main.js +++ /dev/null @@ -1,143 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var copy = require( '@stdlib/array-base-copy-indexed' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require('@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Broadcasts an ndarray to a specified shape. -* -* ## Notes -* -* - The 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. -* -* @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 = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] ); -* // throws -*/ -function broadcastArray( arr, shape ) { - var strides; - var dim; - var sh; - var st; - var N; - var M; - var d; - var i; - var j; - - N = shape.length; - sh = getShape( arr, false ); - M = sh.length; - if ( N < M ) { - throw new Error( format('0i50Z') ); - } - // Initialize a strides array... - strides = []; - for ( i = 0; i < N; i++ ) { - strides.push( 0 ); - } - // Determine the output array strides... - st = getStrides( arr, false ); - for ( i = N-1; i >= 0; i-- ) { - j = M - N + i; - if ( j < 0 ) { - // Prepended singleton dimension; stride is zero... - continue; - } - d = sh[ j ]; - dim = shape[ i ]; - if ( dim !== 0 && dim < d ) { - throw new Error( format( '0i55F', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); - } - if ( d === dim ) { - strides[ i ] = st[ j ]; - } else if ( d === 1 ) { - // In order to broadcast dimensions, we set the stride for that dimension to zero... - strides[ i ] = 0; - } else { - // At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when "tiling" an array; e.g., `dim=4` and `d=2`)... - throw new Error( format( '0i55G', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); - } - } - return ndarray( getDType( arr ), getData( arr ), copy( shape ), strides, getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len -} - - -// EXPORTS // - -module.exports = broadcastArray; diff --git a/package.json b/package.json index 79c6b13..967cb3b 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Broadcast an ndarray to a specified 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,46 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-copy-indexed": "^0.2.1", - "@stdlib/ndarray-base-ctor": "^0.2.1", - "@stdlib/ndarray-base-data-buffer": "^0.2.1", - "@stdlib/ndarray-base-dtype": "^0.2.1", - "@stdlib/ndarray-base-offset": "^0.2.1", - "@stdlib/ndarray-base-order": "^0.2.1", - "@stdlib/ndarray-base-shape": "^0.2.1", - "@stdlib/ndarray-base-strides": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.2.1", - "@stdlib/assert-is-ndarray-like": "^0.2.1", - "@stdlib/ndarray-array": "^0.2.0", - "@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", @@ -92,7 +29,6 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..92694e8 --- /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 97decdb..0000000 --- a/test/test.js +++ /dev/null @@ -1,511 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 broadcastArray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastArray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a desired shape which has fewer dimensions than 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() { - broadcastArray( 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() { - broadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape and an input array shape 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() { - broadcastArray( x, value ); - }; - } -}); - -tape( 'the function returns a "base" ndarray instance', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = broadcastArray( 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 = broadcastArray( 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.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, 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 = broadcastArray( x, expected ); - - actual = y.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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 ccfccebcb005dfebd57c4729a87b925788c9bf66 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 19:22:51 +0000 Subject: [PATCH 46/91] Update README.md for ESM bundle v0.2.1 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 40eb54e..feabb94 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ limitations under the License. ## Usage ```javascript -import broadcastArray from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@esm/index.mjs'; +import broadcastArray from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@v0.2.1-esm/index.mjs'; ``` #### broadcastArray( arr, shape ) @@ -107,7 +107,7 @@ var y = broadcastArray( 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 broadcastArray from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@esm/index.mjs'; +import broadcastArray from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@v0.2.1-esm/index.mjs'; // Create a 2x2 array: var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); From 1af0a067280c2afe924aa7656a408ab9b4227983 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 19:22:52 +0000 Subject: [PATCH 47/91] Auto-generated commit --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index feabb94..75317cf 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,11 @@ limitations under the License. ## Usage +```javascript +import broadcastArray from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-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-broadcast-array/tags). For example, + ```javascript import broadcastArray from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@v0.2.1-esm/index.mjs'; ``` @@ -107,7 +112,7 @@ var y = broadcastArray( 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 broadcastArray from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@v0.2.1-esm/index.mjs'; +import broadcastArray from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@esm/index.mjs'; // Create a 2x2 array: var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); From e41083b915600b406eaa0fc2fe5bc8cd65d33eb3 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Mar 2024 07:45:56 +0000 Subject: [PATCH 48/91] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index 20e9b81..3e61be9 100644 --- a/lib/main.js +++ b/lib/main.js @@ -28,7 +28,7 @@ var getOffset = require( '@stdlib/ndarray-base-offset' ); var getOrder = require( '@stdlib/ndarray-base-order' ); var getDType = require( '@stdlib/ndarray-base-dtype' ); var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -104,7 +104,7 @@ function broadcastArray( arr, shape ) { sh = getShape( arr, false ); M = sh.length; if ( N < M ) { - throw new Error( 'invalid argument. Cannot broadcast an array to a shape having fewer dimensions. Arrays can only be broadcasted to shapes having the same or more dimensions.' ); + throw new Error( format('0i50Z') ); } // Initialize a strides array... strides = []; @@ -122,7 +122,7 @@ function broadcastArray( arr, shape ) { d = sh[ j ]; dim = shape[ i ]; if ( dim !== 0 && dim < d ) { - throw new Error( format( 'invalid argument. Input array cannot be broadcast to the specified shape, as the specified shape has a dimension whose size is less than the size of the corresponding dimension in the input array. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); + throw new Error( format( '0i55F', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); } if ( d === dim ) { strides[ i ] = st[ j ]; @@ -131,7 +131,7 @@ function broadcastArray( arr, shape ) { strides[ i ] = 0; } else { // At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when "tiling" an array; e.g., `dim=4` and `d=2`)... - throw new Error( format( 'invalid argument. Input array and the specified shape are broadcast incompatible. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); + throw new Error( format( '0i55G', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); } } return ndarray( getDType( arr ), getData( arr ), copy( shape ), strides, getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len diff --git a/package.json b/package.json index a9a4de6..c63d0b6 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "@stdlib/ndarray-base-order": "^0.2.1", "@stdlib/ndarray-base-shape": "^0.2.1", "@stdlib/ndarray-base-strides": "^0.2.1", - "@stdlib/string-format": "^0.2.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1", "@stdlib/types": "^0.3.2", "@stdlib/error-tools-fmtprodmsg": "^0.2.1" }, From e8b56449ee87e3ecca9ed15aa50f4726dfd5a0d2 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Mar 2024 13:28:13 +0000 Subject: [PATCH 49/91] Remove files --- index.d.ts | 80 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4927 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 89664bc..0000000 --- a/index.d.ts +++ /dev/null @@ -1,80 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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. -* -* ## Notes -* -* - The function throws an error if a provided ndarray is incompatible with a provided shape. -* - The 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. -* - The returned array is a "base" ndarray, and, thus, the returned array 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 always returns a new ndarray instance even if the input ndarray shape and the desired shape are the same. -* -* @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 -* @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 = broadcastArray( 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 broadcastArray( arr: ndarray, shape: ArrayLike ): ndarray; - - -// EXPORTS // - -export = broadcastArray; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 84f7fb9..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 s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy-indexed@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function j(j,a){var h,p,f,l,v,b,c,g,x;if((v=a.length)<(b=(f=e(j,!1)).length))throw new Error(m("0i50Z"));for(h=[],g=0;g=0;g--)if(!((x=b-v+g)<0)){if(c=f[x],0!==(p=a[g])&&p\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction broadcastArray( arr, shape ) {\n\tvar strides;\n\tvar dim;\n\tvar sh;\n\tvar st;\n\tvar N;\n\tvar M;\n\tvar d;\n\tvar i;\n\tvar j;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\tM = sh.length;\n\tif ( N < M ) {\n\t\tthrow new Error( format('0i50Z') );\n\t}\n\t// Initialize a strides array...\n\tstrides = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tstrides.push( 0 );\n\t}\n\t// Determine the output array strides...\n\tst = getStrides( arr, false );\n\tfor ( i = N-1; i >= 0; i-- ) {\n\t\tj = M - N + i;\n\t\tif ( j < 0 ) {\n\t\t\t// Prepended singleton dimension; stride is zero...\n\t\t\tcontinue;\n\t\t}\n\t\td = sh[ j ];\n\t\tdim = shape[ i ];\n\t\tif ( dim !== 0 && dim < d ) {\n\t\t\tthrow new Error( format( '0i55F', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t\tif ( d === dim ) {\n\t\t\tstrides[ i ] = st[ j ];\n\t\t} else if ( d === 1 ) {\n\t\t\t// In order to broadcast dimensions, we set the stride for that dimension to zero...\n\t\t\tstrides[ i ] = 0;\n\t\t} else {\n\t\t\t// At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when \"tiling\" an array; e.g., `dim=4` and `d=2`)...\n\t\t\tthrow new Error( format( '0i55G', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t}\n\treturn ndarray( getDType( arr ), getData( arr ), copy( shape ), strides, getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nexport default broadcastArray;\n"],"names":["broadcastArray","arr","shape","strides","dim","sh","st","N","M","d","i","j","length","getShape","Error","format","push","getStrides","copy","join","ndarray","getDType","getData","getOffset","getOrder"],"mappings":";;s1BA2FA,SAASA,EAAgBC,EAAKC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAJ,EAAIL,EAAMU,SAEVJ,GADAH,EAAKQ,EAAUZ,GAAK,IACbW,QAEN,MAAM,IAAIE,MAAOC,EAAO,UAIzB,IADAZ,EAAU,GACJO,EAAI,EAAGA,EAAIH,EAAGG,IACnBP,EAAQa,KAAM,GAIf,IADAV,EAAKW,EAAYhB,GAAK,GAChBS,EAAIH,EAAE,EAAGG,GAAK,EAAGA,IAEtB,MADAC,EAAIH,EAAID,EAAIG,GACH,GAAT,CAMA,GAFAD,EAAIJ,EAAIM,GAEK,KADbP,EAAMF,EAAOQ,KACKN,EAAMK,EACvB,MAAM,IAAIK,MAAOC,EAAQ,QAASG,EAAMb,GAAKc,KAAM,MAAQD,EAAMhB,GAAQiB,KAAM,MAAQT,IAExF,GAAKD,IAAML,EACVD,EAASO,GAAMJ,EAAIK,OACb,IAAW,IAANF,EAKX,MAAM,IAAIK,MAAOC,EAAQ,QAASG,EAAMb,GAAKc,KAAM,MAAQD,EAAMhB,GAAQiB,KAAM,MAAQT,IAHvFP,EAASO,GAAM,CAIf,CAdA,CAgBF,OAAOU,EAASC,EAAUpB,GAAOqB,EAASrB,GAAOiB,EAAMhB,GAASC,EAASoB,EAAWtB,GAAOuB,EAAUvB,GACtG"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 92694e8..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From e77bc3314007e7f9c48dda2b3ab8393deaae9e50 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Mar 2024 13:28:39 +0000 Subject: [PATCH 50/91] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 ---- .github/workflows/publish.yml | 249 -- .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 132 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 229 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 49 +- SECURITY.md | 5 - benchmark/benchmark.js | 161 - 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 | 65 - docs/types/test.ts | 94 - examples/index.js | 49 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 68 - lib/main.js | 143 - package.json | 68 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 511 --- 44 files changed, 4870 insertions(+), 4569 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 (96%) 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 d3d4226..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-03-01T05:36:18.807Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 6c59584..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-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 7ab66d5..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-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 e1434bb..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: '28 4 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 9106b5d..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -177,7 +168,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]. @@ -240,11 +231,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-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 d0243ca..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,161 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 broadcastArray = 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 = broadcastArray( 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', 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 = broadcastArray( 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', 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 = broadcastArray( 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(); -}); diff --git a/benchmark/benchmark.ndims.js b/benchmark/benchmark.ndims.js deleted file mode 100644 index 9530251..0000000 --- a/benchmark/benchmark.ndims.js +++ /dev/null @@ -1,110 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 broadcastArray = 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 = broadcastArray( 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 f51adca..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-array" -%% click B href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-array -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-array/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-array/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-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 a9d3107..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import broadcastArray from '../docs/types/index'; -export = broadcastArray; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index e7736e3..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var m=function(a,r){return function(){return r||a((r={exports:{}}).exports,r),r.exports}};var c=m(function(x,f){ -var t=require('@stdlib/array-base-copy-indexed/dist'),g=require('@stdlib/ndarray-base-ctor/dist'),l=require('@stdlib/ndarray-base-shape/dist'),y=require('@stdlib/ndarray-base-strides/dist'),q=require('@stdlib/ndarray-base-offset/dist'),b=require('@stdlib/ndarray-base-order/dist'),w=require('@stdlib/ndarray-base-dtype/dist'),D=require('@stdlib/ndarray-base-data-buffer/dist'),p=require('@stdlib/error-tools-fmtprodmsg/dist');function j(a,r){var i,o,s,v,n,u,d,e,h;if(n=r.length,s=l(a,!1),u=s.length,n=0;e--)if(h=u-n+e,!(h<0)){if(d=s[h],o=r[e],o!==0&&o\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction broadcastArray( arr, shape ) {\n\tvar strides;\n\tvar dim;\n\tvar sh;\n\tvar st;\n\tvar N;\n\tvar M;\n\tvar d;\n\tvar i;\n\tvar j;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\tM = sh.length;\n\tif ( N < M ) {\n\t\tthrow new Error( 'invalid argument. Cannot broadcast an array to a shape having fewer dimensions. Arrays can only be broadcasted to shapes having the same or more dimensions.' );\n\t}\n\t// Initialize a strides array...\n\tstrides = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tstrides.push( 0 );\n\t}\n\t// Determine the output array strides...\n\tst = getStrides( arr, false );\n\tfor ( i = N-1; i >= 0; i-- ) {\n\t\tj = M - N + i;\n\t\tif ( j < 0 ) {\n\t\t\t// Prepended singleton dimension; stride is zero...\n\t\t\tcontinue;\n\t\t}\n\t\td = sh[ j ];\n\t\tdim = shape[ i ];\n\t\tif ( dim !== 0 && dim < d ) {\n\t\t\tthrow new Error( format( 'invalid argument. Input array cannot be broadcast to the specified shape, as the specified shape has a dimension whose size is less than the size of the corresponding dimension in the input array. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t\tif ( d === dim ) {\n\t\t\tstrides[ i ] = st[ j ];\n\t\t} else if ( d === 1 ) {\n\t\t\t// In order to broadcast dimensions, we set the stride for that dimension to zero...\n\t\t\tstrides[ i ] = 0;\n\t\t} else {\n\t\t\t// At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when \"tiling\" an array; e.g., `dim=4` and `d=2`)...\n\t\t\tthrow new Error( format( 'invalid argument. Input array and the specified shape are broadcast incompatible. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t}\n\treturn ndarray( getDType( arr ), getData( arr ), copy( shape ), strides, getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nmodule.exports = broadcastArray;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast an ndarray to a specified shape.\n*\n* @module @stdlib/ndarray-base-broadcast-array\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var broadcastArray = require( '@stdlib/ndarray-base-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 = broadcastArray( 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,EAAO,QAAS,iCAAkC,EAClDC,EAAU,QAAS,2BAA4B,EAC/CC,EAAW,QAAS,4BAA6B,EACjDC,EAAa,QAAQ,8BAA+B,EACpDC,EAAY,QAAS,6BAA8B,EACnDC,EAAW,QAAS,4BAA6B,EACjDC,EAAW,QAAS,4BAA6B,EACjDC,EAAU,QAAS,kCAAmC,EACtDC,EAAS,QAAS,uBAAwB,EA6D9C,SAASC,EAAgBC,EAAKC,EAAQ,CACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACA,EACAC,EACAC,EAKJ,GAHAH,EAAIL,EAAM,OACVG,EAAKZ,EAAUQ,EAAK,EAAM,EAC1BO,EAAIH,EAAG,OACFE,EAAIC,EACR,MAAM,IAAI,MAAO,8JAA+J,EAIjL,IADAL,EAAU,CAAC,EACLM,EAAI,EAAGA,EAAIF,EAAGE,IACnBN,EAAQ,KAAM,CAAE,EAIjB,IADAG,EAAKZ,EAAYO,EAAK,EAAM,EACtBQ,EAAIF,EAAE,EAAGE,GAAK,EAAGA,IAEtB,GADAC,EAAIF,EAAID,EAAIE,EACP,EAAAC,EAAI,GAMT,IAFA,EAAIL,EAAIK,CAAE,EACVN,EAAMF,EAAOO,CAAE,EACVL,IAAQ,GAAKA,EAAM,EACvB,MAAM,IAAI,MAAOL,EAAQ,8PAA+PR,EAAMc,CAAG,EAAE,KAAM,IAAK,EAAGd,EAAMW,CAAM,EAAE,KAAM,IAAK,EAAGO,CAAE,CAAE,EAElV,GAAK,IAAML,EACVD,EAASM,CAAE,EAAIH,EAAII,CAAE,UACV,IAAM,EAEjBP,EAASM,CAAE,EAAI,MAGf,OAAM,IAAI,MAAOV,EAAQ,2IAA4IR,EAAMc,CAAG,EAAE,KAAM,IAAK,EAAGd,EAAMW,CAAM,EAAE,KAAM,IAAK,EAAGO,CAAE,CAAE,EAGhO,OAAOjB,EAASK,EAAUI,CAAI,EAAGH,EAASG,CAAI,EAAGV,EAAMW,CAAM,EAAGC,EAASR,EAAWM,CAAI,EAAGL,EAAUK,CAAI,CAAE,CAC5G,CAKAX,EAAO,QAAUU,IChFjB,IAAIW,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "copy", "ndarray", "getShape", "getStrides", "getOffset", "getOrder", "getDType", "getData", "format", "broadcastArray", "arr", "shape", "strides", "dim", "sh", "st", "N", "M", "i", "j", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index db0f44c..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,65 +0,0 @@ - -{{alias}}( arr, shape ) - Broadcasts an ndarray to a specified shape. - - The 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. - - The returned array is a "base" ndarray, and, thus, the returned array 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. - - The function always returns a new ndarray instance even if the input ndarray - shape and the desired shape are the same. - - 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 4041dc7..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,94 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 broadcastArray = 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(); - - broadcastArray( x, [ 2, 2, 2 ] ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is not provided a first argument which is an ndarray... -{ - broadcastArray( '5', [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( 5, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( true, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( false, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( null, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( {}, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( [ '5' ], [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( ( 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(); - - broadcastArray( x, '5' ); // $ExpectError - broadcastArray( x, 5 ); // $ExpectError - broadcastArray( x, true ); // $ExpectError - broadcastArray( x, false ); // $ExpectError - broadcastArray( x, null ); // $ExpectError - broadcastArray( x, {} ); // $ExpectError - broadcastArray( x, [ '5' ] ); // $ExpectError - broadcastArray( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - - broadcastArray(); // $ExpectError - broadcastArray( x ); // $ExpectError - broadcastArray( x, [ 1, 2, 3 ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index f0dc7b6..0000000 --- a/examples/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 broadcastArray = require( './../lib' ); - -// Create a 2x2 array: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -// returns - -// Broadcast the array to 3x2x2: -var y = broadcastArray( 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 sub; -var v; -var i; -for ( i = 0; i < N; i++ ) { - v = y.iget( i ); - sub = ind2sub( sh, i ); - console.log( 'Y[%s] = %d', sub.join( ', ' ), v ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index 672e358..89664bc 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..d23160e --- /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 s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy-indexed@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function j(j,a){var h,p,f,l,v,b,c,g,x;if((v=a.length)<(b=(f=e(j,!1)).length))throw new Error(m("0i50Z"));for(h=[],g=0;g=0;g--)if(!((x=b-v+g)<0)){if(c=f[x],0!==(p=a[g])&&p\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction broadcastArray( arr, shape ) {\n\tvar strides;\n\tvar dim;\n\tvar sh;\n\tvar st;\n\tvar N;\n\tvar M;\n\tvar d;\n\tvar i;\n\tvar j;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\tM = sh.length;\n\tif ( N < M ) {\n\t\tthrow new Error( format('0i50Z') );\n\t}\n\t// Initialize a strides array...\n\tstrides = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tstrides.push( 0 );\n\t}\n\t// Determine the output array strides...\n\tst = getStrides( arr, false );\n\tfor ( i = N-1; i >= 0; i-- ) {\n\t\tj = M - N + i;\n\t\tif ( j < 0 ) {\n\t\t\t// Prepended singleton dimension; stride is zero...\n\t\t\tcontinue;\n\t\t}\n\t\td = sh[ j ];\n\t\tdim = shape[ i ];\n\t\tif ( dim !== 0 && dim < d ) {\n\t\t\tthrow new Error( format( '0i55F', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t\tif ( d === dim ) {\n\t\t\tstrides[ i ] = st[ j ];\n\t\t} else if ( d === 1 ) {\n\t\t\t// In order to broadcast dimensions, we set the stride for that dimension to zero...\n\t\t\tstrides[ i ] = 0;\n\t\t} else {\n\t\t\t// At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when \"tiling\" an array; e.g., `dim=4` and `d=2`)...\n\t\t\tthrow new Error( format( '0i55G', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t}\n\treturn ndarray( getDType( arr ), getData( arr ), copy( shape ), strides, getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nexport default broadcastArray;\n"],"names":["broadcastArray","arr","shape","strides","dim","sh","st","N","M","d","i","j","length","getShape","Error","format","push","getStrides","copy","join","ndarray","getDType","getData","getOffset","getOrder"],"mappings":";;s1BA2FA,SAASA,EAAgBC,EAAKC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAJ,EAAIL,EAAMU,SAEVJ,GADAH,EAAKQ,EAAUZ,GAAK,IACbW,QAEN,MAAM,IAAIE,MAAOC,EAAO,UAIzB,IADAZ,EAAU,GACJO,EAAI,EAAGA,EAAIH,EAAGG,IACnBP,EAAQa,KAAM,GAIf,IADAV,EAAKW,EAAYhB,GAAK,GAChBS,EAAIH,EAAE,EAAGG,GAAK,EAAGA,IAEtB,MADAC,EAAIH,EAAID,EAAIG,GACH,GAAT,CAMA,GAFAD,EAAIJ,EAAIM,GAEK,KADbP,EAAMF,EAAOQ,KACKN,EAAMK,EACvB,MAAM,IAAIK,MAAOC,EAAQ,QAASG,EAAMb,GAAKc,KAAM,MAAQD,EAAMhB,GAAQiB,KAAM,MAAQT,IAExF,GAAKD,IAAML,EACVD,EAASO,GAAMJ,EAAIK,OACb,IAAW,IAANF,EAKX,MAAM,IAAIK,MAAOC,EAAQ,QAASG,EAAMb,GAAKc,KAAM,MAAQD,EAAMhB,GAAQiB,KAAM,MAAQT,IAHvFP,EAASO,GAAM,CAIf,CAdA,CAgBF,OAAOU,EAASC,EAAUpB,GAAOqB,EAASrB,GAAOiB,EAAMhB,GAASC,EAASoB,EAAWtB,GAAOuB,EAAUvB,GACtG"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index b6aaa86..0000000 --- a/lib/index.js +++ /dev/null @@ -1,68 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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. -* -* @module @stdlib/ndarray-base-broadcast-array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var broadcastArray = require( '@stdlib/ndarray-base-broadcast-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = broadcastArray( 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 3e61be9..0000000 --- a/lib/main.js +++ /dev/null @@ -1,143 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var copy = require( '@stdlib/array-base-copy-indexed' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require('@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Broadcasts an ndarray to a specified shape. -* -* ## Notes -* -* - The 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. -* -* @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 = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] ); -* // throws -*/ -function broadcastArray( arr, shape ) { - var strides; - var dim; - var sh; - var st; - var N; - var M; - var d; - var i; - var j; - - N = shape.length; - sh = getShape( arr, false ); - M = sh.length; - if ( N < M ) { - throw new Error( format('0i50Z') ); - } - // Initialize a strides array... - strides = []; - for ( i = 0; i < N; i++ ) { - strides.push( 0 ); - } - // Determine the output array strides... - st = getStrides( arr, false ); - for ( i = N-1; i >= 0; i-- ) { - j = M - N + i; - if ( j < 0 ) { - // Prepended singleton dimension; stride is zero... - continue; - } - d = sh[ j ]; - dim = shape[ i ]; - if ( dim !== 0 && dim < d ) { - throw new Error( format( '0i55F', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); - } - if ( d === dim ) { - strides[ i ] = st[ j ]; - } else if ( d === 1 ) { - // In order to broadcast dimensions, we set the stride for that dimension to zero... - strides[ i ] = 0; - } else { - // At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when "tiling" an array; e.g., `dim=4` and `d=2`)... - throw new Error( format( '0i55G', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); - } - } - return ndarray( getDType( arr ), getData( arr ), copy( shape ), strides, getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len -} - - -// EXPORTS // - -module.exports = broadcastArray; diff --git a/package.json b/package.json index c63d0b6..967cb3b 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Broadcast an ndarray to a specified 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,46 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-copy-indexed": "^0.2.1", - "@stdlib/ndarray-base-ctor": "^0.2.1", - "@stdlib/ndarray-base-data-buffer": "^0.2.1", - "@stdlib/ndarray-base-dtype": "^0.2.1", - "@stdlib/ndarray-base-offset": "^0.2.1", - "@stdlib/ndarray-base-order": "^0.2.1", - "@stdlib/ndarray-base-shape": "^0.2.1", - "@stdlib/ndarray-base-strides": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.2.1", - "@stdlib/assert-is-ndarray-like": "^0.2.1", - "@stdlib/ndarray-array": "^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", @@ -92,7 +29,6 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..b2f2533 --- /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 97decdb..0000000 --- a/test/test.js +++ /dev/null @@ -1,511 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 broadcastArray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastArray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a desired shape which has fewer dimensions than 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() { - broadcastArray( 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() { - broadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape and an input array shape 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() { - broadcastArray( x, value ); - }; - } -}); - -tape( 'the function returns a "base" ndarray instance', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = broadcastArray( 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 = broadcastArray( 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.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, 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 = broadcastArray( x, expected ); - - actual = y.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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 13ba51f0825538e76729eab5b4931feda83cd3cb Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 07:04:25 +0000 Subject: [PATCH 51/91] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index 20e9b81..3e61be9 100644 --- a/lib/main.js +++ b/lib/main.js @@ -28,7 +28,7 @@ var getOffset = require( '@stdlib/ndarray-base-offset' ); var getOrder = require( '@stdlib/ndarray-base-order' ); var getDType = require( '@stdlib/ndarray-base-dtype' ); var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -104,7 +104,7 @@ function broadcastArray( arr, shape ) { sh = getShape( arr, false ); M = sh.length; if ( N < M ) { - throw new Error( 'invalid argument. Cannot broadcast an array to a shape having fewer dimensions. Arrays can only be broadcasted to shapes having the same or more dimensions.' ); + throw new Error( format('0i50Z') ); } // Initialize a strides array... strides = []; @@ -122,7 +122,7 @@ function broadcastArray( arr, shape ) { d = sh[ j ]; dim = shape[ i ]; if ( dim !== 0 && dim < d ) { - throw new Error( format( 'invalid argument. Input array cannot be broadcast to the specified shape, as the specified shape has a dimension whose size is less than the size of the corresponding dimension in the input array. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); + throw new Error( format( '0i55F', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); } if ( d === dim ) { strides[ i ] = st[ j ]; @@ -131,7 +131,7 @@ function broadcastArray( arr, shape ) { strides[ i ] = 0; } else { // At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when "tiling" an array; e.g., `dim=4` and `d=2`)... - throw new Error( format( 'invalid argument. Input array and the specified shape are broadcast incompatible. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); + throw new Error( format( '0i55G', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); } } return ndarray( getDType( arr ), getData( arr ), copy( shape ), strides, getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len diff --git a/package.json b/package.json index a9a4de6..c63d0b6 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "@stdlib/ndarray-base-order": "^0.2.1", "@stdlib/ndarray-base-shape": "^0.2.1", "@stdlib/ndarray-base-strides": "^0.2.1", - "@stdlib/string-format": "^0.2.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1", "@stdlib/types": "^0.3.2", "@stdlib/error-tools-fmtprodmsg": "^0.2.1" }, From 76fb328dcf3027514d647d4d57c346e7c378aa26 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 12:24:38 +0000 Subject: [PATCH 52/91] Remove files --- index.d.ts | 80 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4927 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 89664bc..0000000 --- a/index.d.ts +++ /dev/null @@ -1,80 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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. -* -* ## Notes -* -* - The function throws an error if a provided ndarray is incompatible with a provided shape. -* - The 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. -* - The returned array is a "base" ndarray, and, thus, the returned array 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 always returns a new ndarray instance even if the input ndarray shape and the desired shape are the same. -* -* @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 -* @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 = broadcastArray( 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 broadcastArray( arr: ndarray, shape: ArrayLike ): ndarray; - - -// EXPORTS // - -export = broadcastArray; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index d23160e..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 s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy-indexed@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function j(j,a){var h,p,f,l,v,b,c,g,x;if((v=a.length)<(b=(f=e(j,!1)).length))throw new Error(m("0i50Z"));for(h=[],g=0;g=0;g--)if(!((x=b-v+g)<0)){if(c=f[x],0!==(p=a[g])&&p\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction broadcastArray( arr, shape ) {\n\tvar strides;\n\tvar dim;\n\tvar sh;\n\tvar st;\n\tvar N;\n\tvar M;\n\tvar d;\n\tvar i;\n\tvar j;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\tM = sh.length;\n\tif ( N < M ) {\n\t\tthrow new Error( format('0i50Z') );\n\t}\n\t// Initialize a strides array...\n\tstrides = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tstrides.push( 0 );\n\t}\n\t// Determine the output array strides...\n\tst = getStrides( arr, false );\n\tfor ( i = N-1; i >= 0; i-- ) {\n\t\tj = M - N + i;\n\t\tif ( j < 0 ) {\n\t\t\t// Prepended singleton dimension; stride is zero...\n\t\t\tcontinue;\n\t\t}\n\t\td = sh[ j ];\n\t\tdim = shape[ i ];\n\t\tif ( dim !== 0 && dim < d ) {\n\t\t\tthrow new Error( format( '0i55F', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t\tif ( d === dim ) {\n\t\t\tstrides[ i ] = st[ j ];\n\t\t} else if ( d === 1 ) {\n\t\t\t// In order to broadcast dimensions, we set the stride for that dimension to zero...\n\t\t\tstrides[ i ] = 0;\n\t\t} else {\n\t\t\t// At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when \"tiling\" an array; e.g., `dim=4` and `d=2`)...\n\t\t\tthrow new Error( format( '0i55G', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t}\n\treturn ndarray( getDType( arr ), getData( arr ), copy( shape ), strides, getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nexport default broadcastArray;\n"],"names":["broadcastArray","arr","shape","strides","dim","sh","st","N","M","d","i","j","length","getShape","Error","format","push","getStrides","copy","join","ndarray","getDType","getData","getOffset","getOrder"],"mappings":";;s1BA2FA,SAASA,EAAgBC,EAAKC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAJ,EAAIL,EAAMU,SAEVJ,GADAH,EAAKQ,EAAUZ,GAAK,IACbW,QAEN,MAAM,IAAIE,MAAOC,EAAO,UAIzB,IADAZ,EAAU,GACJO,EAAI,EAAGA,EAAIH,EAAGG,IACnBP,EAAQa,KAAM,GAIf,IADAV,EAAKW,EAAYhB,GAAK,GAChBS,EAAIH,EAAE,EAAGG,GAAK,EAAGA,IAEtB,MADAC,EAAIH,EAAID,EAAIG,GACH,GAAT,CAMA,GAFAD,EAAIJ,EAAIM,GAEK,KADbP,EAAMF,EAAOQ,KACKN,EAAMK,EACvB,MAAM,IAAIK,MAAOC,EAAQ,QAASG,EAAMb,GAAKc,KAAM,MAAQD,EAAMhB,GAAQiB,KAAM,MAAQT,IAExF,GAAKD,IAAML,EACVD,EAASO,GAAMJ,EAAIK,OACb,IAAW,IAANF,EAKX,MAAM,IAAIK,MAAOC,EAAQ,QAASG,EAAMb,GAAKc,KAAM,MAAQD,EAAMhB,GAAQiB,KAAM,MAAQT,IAHvFP,EAASO,GAAM,CAIf,CAdA,CAgBF,OAAOU,EAASC,EAAUpB,GAAOqB,EAASrB,GAAOiB,EAAMhB,GAASC,EAASoB,EAAWtB,GAAOuB,EAAUvB,GACtG"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index b2f2533..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From bf9e5752f9c50cd59846595f9e7dff7f484c75c5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 12:25:03 +0000 Subject: [PATCH 53/91] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 ---- .github/workflows/publish.yml | 249 -- .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 132 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 49 +- SECURITY.md | 5 - benchmark/benchmark.js | 161 - 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 | 65 - docs/types/test.ts | 94 - examples/index.js | 49 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 68 - lib/main.js | 143 - package.json | 68 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 511 --- 44 files changed, 4870 insertions(+), 4572 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 (96%) 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 87e5a76..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-04-01T04:55:07.457Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 6c59584..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-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 7ab66d5..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-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 e1434bb..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: '28 4 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index ec90164..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -177,7 +168,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]. @@ -240,11 +231,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-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 d0243ca..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,161 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 broadcastArray = 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 = broadcastArray( 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', 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 = broadcastArray( 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', 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 = broadcastArray( 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(); -}); diff --git a/benchmark/benchmark.ndims.js b/benchmark/benchmark.ndims.js deleted file mode 100644 index 9530251..0000000 --- a/benchmark/benchmark.ndims.js +++ /dev/null @@ -1,110 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 broadcastArray = 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 = broadcastArray( 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 f51adca..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-array" -%% click B href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-array -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-array/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-array/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-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 a9d3107..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import broadcastArray from '../docs/types/index'; -export = broadcastArray; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index e7736e3..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var m=function(a,r){return function(){return r||a((r={exports:{}}).exports,r),r.exports}};var c=m(function(x,f){ -var t=require('@stdlib/array-base-copy-indexed/dist'),g=require('@stdlib/ndarray-base-ctor/dist'),l=require('@stdlib/ndarray-base-shape/dist'),y=require('@stdlib/ndarray-base-strides/dist'),q=require('@stdlib/ndarray-base-offset/dist'),b=require('@stdlib/ndarray-base-order/dist'),w=require('@stdlib/ndarray-base-dtype/dist'),D=require('@stdlib/ndarray-base-data-buffer/dist'),p=require('@stdlib/error-tools-fmtprodmsg/dist');function j(a,r){var i,o,s,v,n,u,d,e,h;if(n=r.length,s=l(a,!1),u=s.length,n=0;e--)if(h=u-n+e,!(h<0)){if(d=s[h],o=r[e],o!==0&&o\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction broadcastArray( arr, shape ) {\n\tvar strides;\n\tvar dim;\n\tvar sh;\n\tvar st;\n\tvar N;\n\tvar M;\n\tvar d;\n\tvar i;\n\tvar j;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\tM = sh.length;\n\tif ( N < M ) {\n\t\tthrow new Error( 'invalid argument. Cannot broadcast an array to a shape having fewer dimensions. Arrays can only be broadcasted to shapes having the same or more dimensions.' );\n\t}\n\t// Initialize a strides array...\n\tstrides = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tstrides.push( 0 );\n\t}\n\t// Determine the output array strides...\n\tst = getStrides( arr, false );\n\tfor ( i = N-1; i >= 0; i-- ) {\n\t\tj = M - N + i;\n\t\tif ( j < 0 ) {\n\t\t\t// Prepended singleton dimension; stride is zero...\n\t\t\tcontinue;\n\t\t}\n\t\td = sh[ j ];\n\t\tdim = shape[ i ];\n\t\tif ( dim !== 0 && dim < d ) {\n\t\t\tthrow new Error( format( 'invalid argument. Input array cannot be broadcast to the specified shape, as the specified shape has a dimension whose size is less than the size of the corresponding dimension in the input array. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t\tif ( d === dim ) {\n\t\t\tstrides[ i ] = st[ j ];\n\t\t} else if ( d === 1 ) {\n\t\t\t// In order to broadcast dimensions, we set the stride for that dimension to zero...\n\t\t\tstrides[ i ] = 0;\n\t\t} else {\n\t\t\t// At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when \"tiling\" an array; e.g., `dim=4` and `d=2`)...\n\t\t\tthrow new Error( format( 'invalid argument. Input array and the specified shape are broadcast incompatible. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t}\n\treturn ndarray( getDType( arr ), getData( arr ), copy( shape ), strides, getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nmodule.exports = broadcastArray;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast an ndarray to a specified shape.\n*\n* @module @stdlib/ndarray-base-broadcast-array\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var broadcastArray = require( '@stdlib/ndarray-base-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 = broadcastArray( 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,EAAO,QAAS,iCAAkC,EAClDC,EAAU,QAAS,2BAA4B,EAC/CC,EAAW,QAAS,4BAA6B,EACjDC,EAAa,QAAQ,8BAA+B,EACpDC,EAAY,QAAS,6BAA8B,EACnDC,EAAW,QAAS,4BAA6B,EACjDC,EAAW,QAAS,4BAA6B,EACjDC,EAAU,QAAS,kCAAmC,EACtDC,EAAS,QAAS,uBAAwB,EA6D9C,SAASC,EAAgBC,EAAKC,EAAQ,CACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACA,EACAC,EACAC,EAKJ,GAHAH,EAAIL,EAAM,OACVG,EAAKZ,EAAUQ,EAAK,EAAM,EAC1BO,EAAIH,EAAG,OACFE,EAAIC,EACR,MAAM,IAAI,MAAO,8JAA+J,EAIjL,IADAL,EAAU,CAAC,EACLM,EAAI,EAAGA,EAAIF,EAAGE,IACnBN,EAAQ,KAAM,CAAE,EAIjB,IADAG,EAAKZ,EAAYO,EAAK,EAAM,EACtBQ,EAAIF,EAAE,EAAGE,GAAK,EAAGA,IAEtB,GADAC,EAAIF,EAAID,EAAIE,EACP,EAAAC,EAAI,GAMT,IAFA,EAAIL,EAAIK,CAAE,EACVN,EAAMF,EAAOO,CAAE,EACVL,IAAQ,GAAKA,EAAM,EACvB,MAAM,IAAI,MAAOL,EAAQ,8PAA+PR,EAAMc,CAAG,EAAE,KAAM,IAAK,EAAGd,EAAMW,CAAM,EAAE,KAAM,IAAK,EAAGO,CAAE,CAAE,EAElV,GAAK,IAAML,EACVD,EAASM,CAAE,EAAIH,EAAII,CAAE,UACV,IAAM,EAEjBP,EAASM,CAAE,EAAI,MAGf,OAAM,IAAI,MAAOV,EAAQ,2IAA4IR,EAAMc,CAAG,EAAE,KAAM,IAAK,EAAGd,EAAMW,CAAM,EAAE,KAAM,IAAK,EAAGO,CAAE,CAAE,EAGhO,OAAOjB,EAASK,EAAUI,CAAI,EAAGH,EAASG,CAAI,EAAGV,EAAMW,CAAM,EAAGC,EAASR,EAAWM,CAAI,EAAGL,EAAUK,CAAI,CAAE,CAC5G,CAKAX,EAAO,QAAUU,IChFjB,IAAIW,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "copy", "ndarray", "getShape", "getStrides", "getOffset", "getOrder", "getDType", "getData", "format", "broadcastArray", "arr", "shape", "strides", "dim", "sh", "st", "N", "M", "i", "j", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index db0f44c..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,65 +0,0 @@ - -{{alias}}( arr, shape ) - Broadcasts an ndarray to a specified shape. - - The 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. - - The returned array is a "base" ndarray, and, thus, the returned array 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. - - The function always returns a new ndarray instance even if the input ndarray - shape and the desired shape are the same. - - 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 4041dc7..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,94 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 broadcastArray = 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(); - - broadcastArray( x, [ 2, 2, 2 ] ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is not provided a first argument which is an ndarray... -{ - broadcastArray( '5', [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( 5, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( true, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( false, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( null, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( {}, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( [ '5' ], [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( ( 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(); - - broadcastArray( x, '5' ); // $ExpectError - broadcastArray( x, 5 ); // $ExpectError - broadcastArray( x, true ); // $ExpectError - broadcastArray( x, false ); // $ExpectError - broadcastArray( x, null ); // $ExpectError - broadcastArray( x, {} ); // $ExpectError - broadcastArray( x, [ '5' ] ); // $ExpectError - broadcastArray( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - - broadcastArray(); // $ExpectError - broadcastArray( x ); // $ExpectError - broadcastArray( x, [ 1, 2, 3 ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index f0dc7b6..0000000 --- a/examples/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 broadcastArray = require( './../lib' ); - -// Create a 2x2 array: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -// returns - -// Broadcast the array to 3x2x2: -var y = broadcastArray( 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 sub; -var v; -var i; -for ( i = 0; i < N; i++ ) { - v = y.iget( i ); - sub = ind2sub( sh, i ); - console.log( 'Y[%s] = %d', sub.join( ', ' ), v ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index 672e358..89664bc 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..d23160e --- /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 s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy-indexed@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function j(j,a){var h,p,f,l,v,b,c,g,x;if((v=a.length)<(b=(f=e(j,!1)).length))throw new Error(m("0i50Z"));for(h=[],g=0;g=0;g--)if(!((x=b-v+g)<0)){if(c=f[x],0!==(p=a[g])&&p\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction broadcastArray( arr, shape ) {\n\tvar strides;\n\tvar dim;\n\tvar sh;\n\tvar st;\n\tvar N;\n\tvar M;\n\tvar d;\n\tvar i;\n\tvar j;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\tM = sh.length;\n\tif ( N < M ) {\n\t\tthrow new Error( format('0i50Z') );\n\t}\n\t// Initialize a strides array...\n\tstrides = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tstrides.push( 0 );\n\t}\n\t// Determine the output array strides...\n\tst = getStrides( arr, false );\n\tfor ( i = N-1; i >= 0; i-- ) {\n\t\tj = M - N + i;\n\t\tif ( j < 0 ) {\n\t\t\t// Prepended singleton dimension; stride is zero...\n\t\t\tcontinue;\n\t\t}\n\t\td = sh[ j ];\n\t\tdim = shape[ i ];\n\t\tif ( dim !== 0 && dim < d ) {\n\t\t\tthrow new Error( format( '0i55F', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t\tif ( d === dim ) {\n\t\t\tstrides[ i ] = st[ j ];\n\t\t} else if ( d === 1 ) {\n\t\t\t// In order to broadcast dimensions, we set the stride for that dimension to zero...\n\t\t\tstrides[ i ] = 0;\n\t\t} else {\n\t\t\t// At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when \"tiling\" an array; e.g., `dim=4` and `d=2`)...\n\t\t\tthrow new Error( format( '0i55G', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t}\n\treturn ndarray( getDType( arr ), getData( arr ), copy( shape ), strides, getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nexport default broadcastArray;\n"],"names":["broadcastArray","arr","shape","strides","dim","sh","st","N","M","d","i","j","length","getShape","Error","format","push","getStrides","copy","join","ndarray","getDType","getData","getOffset","getOrder"],"mappings":";;s1BA2FA,SAASA,EAAgBC,EAAKC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAJ,EAAIL,EAAMU,SAEVJ,GADAH,EAAKQ,EAAUZ,GAAK,IACbW,QAEN,MAAM,IAAIE,MAAOC,EAAO,UAIzB,IADAZ,EAAU,GACJO,EAAI,EAAGA,EAAIH,EAAGG,IACnBP,EAAQa,KAAM,GAIf,IADAV,EAAKW,EAAYhB,GAAK,GAChBS,EAAIH,EAAE,EAAGG,GAAK,EAAGA,IAEtB,MADAC,EAAIH,EAAID,EAAIG,GACH,GAAT,CAMA,GAFAD,EAAIJ,EAAIM,GAEK,KADbP,EAAMF,EAAOQ,KACKN,EAAMK,EACvB,MAAM,IAAIK,MAAOC,EAAQ,QAASG,EAAMb,GAAKc,KAAM,MAAQD,EAAMhB,GAAQiB,KAAM,MAAQT,IAExF,GAAKD,IAAML,EACVD,EAASO,GAAMJ,EAAIK,OACb,IAAW,IAANF,EAKX,MAAM,IAAIK,MAAOC,EAAQ,QAASG,EAAMb,GAAKc,KAAM,MAAQD,EAAMhB,GAAQiB,KAAM,MAAQT,IAHvFP,EAASO,GAAM,CAIf,CAdA,CAgBF,OAAOU,EAASC,EAAUpB,GAAOqB,EAASrB,GAAOiB,EAAMhB,GAASC,EAASoB,EAAWtB,GAAOuB,EAAUvB,GACtG"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index b6aaa86..0000000 --- a/lib/index.js +++ /dev/null @@ -1,68 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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. -* -* @module @stdlib/ndarray-base-broadcast-array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var broadcastArray = require( '@stdlib/ndarray-base-broadcast-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = broadcastArray( 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 3e61be9..0000000 --- a/lib/main.js +++ /dev/null @@ -1,143 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var copy = require( '@stdlib/array-base-copy-indexed' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require('@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Broadcasts an ndarray to a specified shape. -* -* ## Notes -* -* - The 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. -* -* @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 = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] ); -* // throws -*/ -function broadcastArray( arr, shape ) { - var strides; - var dim; - var sh; - var st; - var N; - var M; - var d; - var i; - var j; - - N = shape.length; - sh = getShape( arr, false ); - M = sh.length; - if ( N < M ) { - throw new Error( format('0i50Z') ); - } - // Initialize a strides array... - strides = []; - for ( i = 0; i < N; i++ ) { - strides.push( 0 ); - } - // Determine the output array strides... - st = getStrides( arr, false ); - for ( i = N-1; i >= 0; i-- ) { - j = M - N + i; - if ( j < 0 ) { - // Prepended singleton dimension; stride is zero... - continue; - } - d = sh[ j ]; - dim = shape[ i ]; - if ( dim !== 0 && dim < d ) { - throw new Error( format( '0i55F', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); - } - if ( d === dim ) { - strides[ i ] = st[ j ]; - } else if ( d === 1 ) { - // In order to broadcast dimensions, we set the stride for that dimension to zero... - strides[ i ] = 0; - } else { - // At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when "tiling" an array; e.g., `dim=4` and `d=2`)... - throw new Error( format( '0i55G', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); - } - } - return ndarray( getDType( arr ), getData( arr ), copy( shape ), strides, getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len -} - - -// EXPORTS // - -module.exports = broadcastArray; diff --git a/package.json b/package.json index c63d0b6..967cb3b 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Broadcast an ndarray to a specified 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,46 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-copy-indexed": "^0.2.1", - "@stdlib/ndarray-base-ctor": "^0.2.1", - "@stdlib/ndarray-base-data-buffer": "^0.2.1", - "@stdlib/ndarray-base-dtype": "^0.2.1", - "@stdlib/ndarray-base-offset": "^0.2.1", - "@stdlib/ndarray-base-order": "^0.2.1", - "@stdlib/ndarray-base-shape": "^0.2.1", - "@stdlib/ndarray-base-strides": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.2.1", - "@stdlib/assert-is-ndarray-like": "^0.2.1", - "@stdlib/ndarray-array": "^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", @@ -92,7 +29,6 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..b2f2533 --- /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 97decdb..0000000 --- a/test/test.js +++ /dev/null @@ -1,511 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 broadcastArray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastArray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a desired shape which has fewer dimensions than 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() { - broadcastArray( 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() { - broadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape and an input array shape 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() { - broadcastArray( x, value ); - }; - } -}); - -tape( 'the function returns a "base" ndarray instance', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = broadcastArray( 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 = broadcastArray( 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.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, 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 = broadcastArray( x, expected ); - - actual = y.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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 6d4c7a9cde54bf7bdcf04cf9b693ae7062d088b5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 12 Apr 2024 03:20:46 +0000 Subject: [PATCH 54/91] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index 20e9b81..3e61be9 100644 --- a/lib/main.js +++ b/lib/main.js @@ -28,7 +28,7 @@ var getOffset = require( '@stdlib/ndarray-base-offset' ); var getOrder = require( '@stdlib/ndarray-base-order' ); var getDType = require( '@stdlib/ndarray-base-dtype' ); var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -104,7 +104,7 @@ function broadcastArray( arr, shape ) { sh = getShape( arr, false ); M = sh.length; if ( N < M ) { - throw new Error( 'invalid argument. Cannot broadcast an array to a shape having fewer dimensions. Arrays can only be broadcasted to shapes having the same or more dimensions.' ); + throw new Error( format('0i50Z') ); } // Initialize a strides array... strides = []; @@ -122,7 +122,7 @@ function broadcastArray( arr, shape ) { d = sh[ j ]; dim = shape[ i ]; if ( dim !== 0 && dim < d ) { - throw new Error( format( 'invalid argument. Input array cannot be broadcast to the specified shape, as the specified shape has a dimension whose size is less than the size of the corresponding dimension in the input array. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); + throw new Error( format( '0i55F', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); } if ( d === dim ) { strides[ i ] = st[ j ]; @@ -131,7 +131,7 @@ function broadcastArray( arr, shape ) { strides[ i ] = 0; } else { // At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when "tiling" an array; e.g., `dim=4` and `d=2`)... - throw new Error( format( 'invalid argument. Input array and the specified shape are broadcast incompatible. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); + throw new Error( format( '0i55G', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); } } return ndarray( getDType( arr ), getData( arr ), copy( shape ), strides, getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len diff --git a/package.json b/package.json index a9a4de6..c63d0b6 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "@stdlib/ndarray-base-order": "^0.2.1", "@stdlib/ndarray-base-shape": "^0.2.1", "@stdlib/ndarray-base-strides": "^0.2.1", - "@stdlib/string-format": "^0.2.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1", "@stdlib/types": "^0.3.2", "@stdlib/error-tools-fmtprodmsg": "^0.2.1" }, From 4419e3885e11c722f41ff1808c5b16f7adbfe0f1 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 12 Apr 2024 08:44:41 +0000 Subject: [PATCH 55/91] Remove files --- index.d.ts | 80 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4927 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 89664bc..0000000 --- a/index.d.ts +++ /dev/null @@ -1,80 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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. -* -* ## Notes -* -* - The function throws an error if a provided ndarray is incompatible with a provided shape. -* - The 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. -* - The returned array is a "base" ndarray, and, thus, the returned array 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 always returns a new ndarray instance even if the input ndarray shape and the desired shape are the same. -* -* @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 -* @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 = broadcastArray( 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 broadcastArray( arr: ndarray, shape: ArrayLike ): ndarray; - - -// EXPORTS // - -export = broadcastArray; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index d23160e..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 s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy-indexed@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function j(j,a){var h,p,f,l,v,b,c,g,x;if((v=a.length)<(b=(f=e(j,!1)).length))throw new Error(m("0i50Z"));for(h=[],g=0;g=0;g--)if(!((x=b-v+g)<0)){if(c=f[x],0!==(p=a[g])&&p\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction broadcastArray( arr, shape ) {\n\tvar strides;\n\tvar dim;\n\tvar sh;\n\tvar st;\n\tvar N;\n\tvar M;\n\tvar d;\n\tvar i;\n\tvar j;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\tM = sh.length;\n\tif ( N < M ) {\n\t\tthrow new Error( format('0i50Z') );\n\t}\n\t// Initialize a strides array...\n\tstrides = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tstrides.push( 0 );\n\t}\n\t// Determine the output array strides...\n\tst = getStrides( arr, false );\n\tfor ( i = N-1; i >= 0; i-- ) {\n\t\tj = M - N + i;\n\t\tif ( j < 0 ) {\n\t\t\t// Prepended singleton dimension; stride is zero...\n\t\t\tcontinue;\n\t\t}\n\t\td = sh[ j ];\n\t\tdim = shape[ i ];\n\t\tif ( dim !== 0 && dim < d ) {\n\t\t\tthrow new Error( format( '0i55F', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t\tif ( d === dim ) {\n\t\t\tstrides[ i ] = st[ j ];\n\t\t} else if ( d === 1 ) {\n\t\t\t// In order to broadcast dimensions, we set the stride for that dimension to zero...\n\t\t\tstrides[ i ] = 0;\n\t\t} else {\n\t\t\t// At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when \"tiling\" an array; e.g., `dim=4` and `d=2`)...\n\t\t\tthrow new Error( format( '0i55G', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t}\n\treturn ndarray( getDType( arr ), getData( arr ), copy( shape ), strides, getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nexport default broadcastArray;\n"],"names":["broadcastArray","arr","shape","strides","dim","sh","st","N","M","d","i","j","length","getShape","Error","format","push","getStrides","copy","join","ndarray","getDType","getData","getOffset","getOrder"],"mappings":";;s1BA2FA,SAASA,EAAgBC,EAAKC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAJ,EAAIL,EAAMU,SAEVJ,GADAH,EAAKQ,EAAUZ,GAAK,IACbW,QAEN,MAAM,IAAIE,MAAOC,EAAO,UAIzB,IADAZ,EAAU,GACJO,EAAI,EAAGA,EAAIH,EAAGG,IACnBP,EAAQa,KAAM,GAIf,IADAV,EAAKW,EAAYhB,GAAK,GAChBS,EAAIH,EAAE,EAAGG,GAAK,EAAGA,IAEtB,MADAC,EAAIH,EAAID,EAAIG,GACH,GAAT,CAMA,GAFAD,EAAIJ,EAAIM,GAEK,KADbP,EAAMF,EAAOQ,KACKN,EAAMK,EACvB,MAAM,IAAIK,MAAOC,EAAQ,QAASG,EAAMb,GAAKc,KAAM,MAAQD,EAAMhB,GAAQiB,KAAM,MAAQT,IAExF,GAAKD,IAAML,EACVD,EAASO,GAAMJ,EAAIK,OACb,IAAW,IAANF,EAKX,MAAM,IAAIK,MAAOC,EAAQ,QAASG,EAAMb,GAAKc,KAAM,MAAQD,EAAMhB,GAAQiB,KAAM,MAAQT,IAHvFP,EAASO,GAAM,CAIf,CAdA,CAgBF,OAAOU,EAASC,EAAUpB,GAAOqB,EAASrB,GAAOiB,EAAMhB,GAASC,EAASoB,EAAWtB,GAAOuB,EAAUvB,GACtG"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index b2f2533..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 5e3548a85dc9a514ace786a2376804ad99714fce Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 12 Apr 2024 08:45:00 +0000 Subject: [PATCH 56/91] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 ---- .github/workflows/publish.yml | 249 -- .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 134 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 49 +- SECURITY.md | 5 - benchmark/benchmark.js | 161 - 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 | 65 - docs/types/test.ts | 94 - examples/index.js | 49 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 68 - lib/main.js | 143 - package.json | 68 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 511 --- 43 files changed, 4870 insertions(+), 4573 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 (96%) 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 6c59584..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-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 7ab66d5..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-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 e1434bb..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: '28 4 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index ec90164..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -177,7 +168,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]. @@ -240,11 +231,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-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 d0243ca..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,161 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 broadcastArray = 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 = broadcastArray( 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', 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 = broadcastArray( 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', 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 = broadcastArray( 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(); -}); diff --git a/benchmark/benchmark.ndims.js b/benchmark/benchmark.ndims.js deleted file mode 100644 index 9530251..0000000 --- a/benchmark/benchmark.ndims.js +++ /dev/null @@ -1,110 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 broadcastArray = 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 = broadcastArray( 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 f51adca..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-array" -%% click B href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-array -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-array/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-array/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-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 a9d3107..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import broadcastArray from '../docs/types/index'; -export = broadcastArray; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index e7736e3..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var m=function(a,r){return function(){return r||a((r={exports:{}}).exports,r),r.exports}};var c=m(function(x,f){ -var t=require('@stdlib/array-base-copy-indexed/dist'),g=require('@stdlib/ndarray-base-ctor/dist'),l=require('@stdlib/ndarray-base-shape/dist'),y=require('@stdlib/ndarray-base-strides/dist'),q=require('@stdlib/ndarray-base-offset/dist'),b=require('@stdlib/ndarray-base-order/dist'),w=require('@stdlib/ndarray-base-dtype/dist'),D=require('@stdlib/ndarray-base-data-buffer/dist'),p=require('@stdlib/error-tools-fmtprodmsg/dist');function j(a,r){var i,o,s,v,n,u,d,e,h;if(n=r.length,s=l(a,!1),u=s.length,n=0;e--)if(h=u-n+e,!(h<0)){if(d=s[h],o=r[e],o!==0&&o\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction broadcastArray( arr, shape ) {\n\tvar strides;\n\tvar dim;\n\tvar sh;\n\tvar st;\n\tvar N;\n\tvar M;\n\tvar d;\n\tvar i;\n\tvar j;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\tM = sh.length;\n\tif ( N < M ) {\n\t\tthrow new Error( 'invalid argument. Cannot broadcast an array to a shape having fewer dimensions. Arrays can only be broadcasted to shapes having the same or more dimensions.' );\n\t}\n\t// Initialize a strides array...\n\tstrides = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tstrides.push( 0 );\n\t}\n\t// Determine the output array strides...\n\tst = getStrides( arr, false );\n\tfor ( i = N-1; i >= 0; i-- ) {\n\t\tj = M - N + i;\n\t\tif ( j < 0 ) {\n\t\t\t// Prepended singleton dimension; stride is zero...\n\t\t\tcontinue;\n\t\t}\n\t\td = sh[ j ];\n\t\tdim = shape[ i ];\n\t\tif ( dim !== 0 && dim < d ) {\n\t\t\tthrow new Error( format( 'invalid argument. Input array cannot be broadcast to the specified shape, as the specified shape has a dimension whose size is less than the size of the corresponding dimension in the input array. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t\tif ( d === dim ) {\n\t\t\tstrides[ i ] = st[ j ];\n\t\t} else if ( d === 1 ) {\n\t\t\t// In order to broadcast dimensions, we set the stride for that dimension to zero...\n\t\t\tstrides[ i ] = 0;\n\t\t} else {\n\t\t\t// At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when \"tiling\" an array; e.g., `dim=4` and `d=2`)...\n\t\t\tthrow new Error( format( 'invalid argument. Input array and the specified shape are broadcast incompatible. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t}\n\treturn ndarray( getDType( arr ), getData( arr ), copy( shape ), strides, getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nmodule.exports = broadcastArray;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast an ndarray to a specified shape.\n*\n* @module @stdlib/ndarray-base-broadcast-array\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var broadcastArray = require( '@stdlib/ndarray-base-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 = broadcastArray( 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,EAAO,QAAS,iCAAkC,EAClDC,EAAU,QAAS,2BAA4B,EAC/CC,EAAW,QAAS,4BAA6B,EACjDC,EAAa,QAAQ,8BAA+B,EACpDC,EAAY,QAAS,6BAA8B,EACnDC,EAAW,QAAS,4BAA6B,EACjDC,EAAW,QAAS,4BAA6B,EACjDC,EAAU,QAAS,kCAAmC,EACtDC,EAAS,QAAS,uBAAwB,EA6D9C,SAASC,EAAgBC,EAAKC,EAAQ,CACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACA,EACAC,EACAC,EAKJ,GAHAH,EAAIL,EAAM,OACVG,EAAKZ,EAAUQ,EAAK,EAAM,EAC1BO,EAAIH,EAAG,OACFE,EAAIC,EACR,MAAM,IAAI,MAAO,8JAA+J,EAIjL,IADAL,EAAU,CAAC,EACLM,EAAI,EAAGA,EAAIF,EAAGE,IACnBN,EAAQ,KAAM,CAAE,EAIjB,IADAG,EAAKZ,EAAYO,EAAK,EAAM,EACtBQ,EAAIF,EAAE,EAAGE,GAAK,EAAGA,IAEtB,GADAC,EAAIF,EAAID,EAAIE,EACP,EAAAC,EAAI,GAMT,IAFA,EAAIL,EAAIK,CAAE,EACVN,EAAMF,EAAOO,CAAE,EACVL,IAAQ,GAAKA,EAAM,EACvB,MAAM,IAAI,MAAOL,EAAQ,8PAA+PR,EAAMc,CAAG,EAAE,KAAM,IAAK,EAAGd,EAAMW,CAAM,EAAE,KAAM,IAAK,EAAGO,CAAE,CAAE,EAElV,GAAK,IAAML,EACVD,EAASM,CAAE,EAAIH,EAAII,CAAE,UACV,IAAM,EAEjBP,EAASM,CAAE,EAAI,MAGf,OAAM,IAAI,MAAOV,EAAQ,2IAA4IR,EAAMc,CAAG,EAAE,KAAM,IAAK,EAAGd,EAAMW,CAAM,EAAE,KAAM,IAAK,EAAGO,CAAE,CAAE,EAGhO,OAAOjB,EAASK,EAAUI,CAAI,EAAGH,EAASG,CAAI,EAAGV,EAAMW,CAAM,EAAGC,EAASR,EAAWM,CAAI,EAAGL,EAAUK,CAAI,CAAE,CAC5G,CAKAX,EAAO,QAAUU,IChFjB,IAAIW,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "copy", "ndarray", "getShape", "getStrides", "getOffset", "getOrder", "getDType", "getData", "format", "broadcastArray", "arr", "shape", "strides", "dim", "sh", "st", "N", "M", "i", "j", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index db0f44c..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,65 +0,0 @@ - -{{alias}}( arr, shape ) - Broadcasts an ndarray to a specified shape. - - The 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. - - The returned array is a "base" ndarray, and, thus, the returned array 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. - - The function always returns a new ndarray instance even if the input ndarray - shape and the desired shape are the same. - - 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 4041dc7..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,94 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 broadcastArray = 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(); - - broadcastArray( x, [ 2, 2, 2 ] ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is not provided a first argument which is an ndarray... -{ - broadcastArray( '5', [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( 5, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( true, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( false, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( null, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( {}, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( [ '5' ], [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( ( 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(); - - broadcastArray( x, '5' ); // $ExpectError - broadcastArray( x, 5 ); // $ExpectError - broadcastArray( x, true ); // $ExpectError - broadcastArray( x, false ); // $ExpectError - broadcastArray( x, null ); // $ExpectError - broadcastArray( x, {} ); // $ExpectError - broadcastArray( x, [ '5' ] ); // $ExpectError - broadcastArray( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - - broadcastArray(); // $ExpectError - broadcastArray( x ); // $ExpectError - broadcastArray( x, [ 1, 2, 3 ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index f0dc7b6..0000000 --- a/examples/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 broadcastArray = require( './../lib' ); - -// Create a 2x2 array: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -// returns - -// Broadcast the array to 3x2x2: -var y = broadcastArray( 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 sub; -var v; -var i; -for ( i = 0; i < N; i++ ) { - v = y.iget( i ); - sub = ind2sub( sh, i ); - console.log( 'Y[%s] = %d', sub.join( ', ' ), v ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index 672e358..89664bc 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..d23160e --- /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 s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy-indexed@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function j(j,a){var h,p,f,l,v,b,c,g,x;if((v=a.length)<(b=(f=e(j,!1)).length))throw new Error(m("0i50Z"));for(h=[],g=0;g=0;g--)if(!((x=b-v+g)<0)){if(c=f[x],0!==(p=a[g])&&p\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction broadcastArray( arr, shape ) {\n\tvar strides;\n\tvar dim;\n\tvar sh;\n\tvar st;\n\tvar N;\n\tvar M;\n\tvar d;\n\tvar i;\n\tvar j;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\tM = sh.length;\n\tif ( N < M ) {\n\t\tthrow new Error( format('0i50Z') );\n\t}\n\t// Initialize a strides array...\n\tstrides = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tstrides.push( 0 );\n\t}\n\t// Determine the output array strides...\n\tst = getStrides( arr, false );\n\tfor ( i = N-1; i >= 0; i-- ) {\n\t\tj = M - N + i;\n\t\tif ( j < 0 ) {\n\t\t\t// Prepended singleton dimension; stride is zero...\n\t\t\tcontinue;\n\t\t}\n\t\td = sh[ j ];\n\t\tdim = shape[ i ];\n\t\tif ( dim !== 0 && dim < d ) {\n\t\t\tthrow new Error( format( '0i55F', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t\tif ( d === dim ) {\n\t\t\tstrides[ i ] = st[ j ];\n\t\t} else if ( d === 1 ) {\n\t\t\t// In order to broadcast dimensions, we set the stride for that dimension to zero...\n\t\t\tstrides[ i ] = 0;\n\t\t} else {\n\t\t\t// At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when \"tiling\" an array; e.g., `dim=4` and `d=2`)...\n\t\t\tthrow new Error( format( '0i55G', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t}\n\treturn ndarray( getDType( arr ), getData( arr ), copy( shape ), strides, getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nexport default broadcastArray;\n"],"names":["broadcastArray","arr","shape","strides","dim","sh","st","N","M","d","i","j","length","getShape","Error","format","push","getStrides","copy","join","ndarray","getDType","getData","getOffset","getOrder"],"mappings":";;s1BA2FA,SAASA,EAAgBC,EAAKC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAJ,EAAIL,EAAMU,SAEVJ,GADAH,EAAKQ,EAAUZ,GAAK,IACbW,QAEN,MAAM,IAAIE,MAAOC,EAAO,UAIzB,IADAZ,EAAU,GACJO,EAAI,EAAGA,EAAIH,EAAGG,IACnBP,EAAQa,KAAM,GAIf,IADAV,EAAKW,EAAYhB,GAAK,GAChBS,EAAIH,EAAE,EAAGG,GAAK,EAAGA,IAEtB,MADAC,EAAIH,EAAID,EAAIG,GACH,GAAT,CAMA,GAFAD,EAAIJ,EAAIM,GAEK,KADbP,EAAMF,EAAOQ,KACKN,EAAMK,EACvB,MAAM,IAAIK,MAAOC,EAAQ,QAASG,EAAMb,GAAKc,KAAM,MAAQD,EAAMhB,GAAQiB,KAAM,MAAQT,IAExF,GAAKD,IAAML,EACVD,EAASO,GAAMJ,EAAIK,OACb,IAAW,IAANF,EAKX,MAAM,IAAIK,MAAOC,EAAQ,QAASG,EAAMb,GAAKc,KAAM,MAAQD,EAAMhB,GAAQiB,KAAM,MAAQT,IAHvFP,EAASO,GAAM,CAIf,CAdA,CAgBF,OAAOU,EAASC,EAAUpB,GAAOqB,EAASrB,GAAOiB,EAAMhB,GAASC,EAASoB,EAAWtB,GAAOuB,EAAUvB,GACtG"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index b6aaa86..0000000 --- a/lib/index.js +++ /dev/null @@ -1,68 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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. -* -* @module @stdlib/ndarray-base-broadcast-array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var broadcastArray = require( '@stdlib/ndarray-base-broadcast-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = broadcastArray( 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 3e61be9..0000000 --- a/lib/main.js +++ /dev/null @@ -1,143 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var copy = require( '@stdlib/array-base-copy-indexed' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require('@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Broadcasts an ndarray to a specified shape. -* -* ## Notes -* -* - The 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. -* -* @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 = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] ); -* // throws -*/ -function broadcastArray( arr, shape ) { - var strides; - var dim; - var sh; - var st; - var N; - var M; - var d; - var i; - var j; - - N = shape.length; - sh = getShape( arr, false ); - M = sh.length; - if ( N < M ) { - throw new Error( format('0i50Z') ); - } - // Initialize a strides array... - strides = []; - for ( i = 0; i < N; i++ ) { - strides.push( 0 ); - } - // Determine the output array strides... - st = getStrides( arr, false ); - for ( i = N-1; i >= 0; i-- ) { - j = M - N + i; - if ( j < 0 ) { - // Prepended singleton dimension; stride is zero... - continue; - } - d = sh[ j ]; - dim = shape[ i ]; - if ( dim !== 0 && dim < d ) { - throw new Error( format( '0i55F', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); - } - if ( d === dim ) { - strides[ i ] = st[ j ]; - } else if ( d === 1 ) { - // In order to broadcast dimensions, we set the stride for that dimension to zero... - strides[ i ] = 0; - } else { - // At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when "tiling" an array; e.g., `dim=4` and `d=2`)... - throw new Error( format( '0i55G', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); - } - } - return ndarray( getDType( arr ), getData( arr ), copy( shape ), strides, getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len -} - - -// EXPORTS // - -module.exports = broadcastArray; diff --git a/package.json b/package.json index c63d0b6..967cb3b 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Broadcast an ndarray to a specified 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,46 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-copy-indexed": "^0.2.1", - "@stdlib/ndarray-base-ctor": "^0.2.1", - "@stdlib/ndarray-base-data-buffer": "^0.2.1", - "@stdlib/ndarray-base-dtype": "^0.2.1", - "@stdlib/ndarray-base-offset": "^0.2.1", - "@stdlib/ndarray-base-order": "^0.2.1", - "@stdlib/ndarray-base-shape": "^0.2.1", - "@stdlib/ndarray-base-strides": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.2.1", - "@stdlib/assert-is-ndarray-like": "^0.2.1", - "@stdlib/ndarray-array": "^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", @@ -92,7 +29,6 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..b2f2533 --- /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 97decdb..0000000 --- a/test/test.js +++ /dev/null @@ -1,511 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 broadcastArray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastArray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a desired shape which has fewer dimensions than 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() { - broadcastArray( 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() { - broadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape and an input array shape 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() { - broadcastArray( x, value ); - }; - } -}); - -tape( 'the function returns a "base" ndarray instance', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = broadcastArray( 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 = broadcastArray( 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.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, 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 = broadcastArray( x, expected ); - - actual = y.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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 5f1c3dea5eeb0409f615b81a6975ae07682004d6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 29 Jul 2024 02:23:45 +0000 Subject: [PATCH 57/91] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index 20e9b81..3e61be9 100644 --- a/lib/main.js +++ b/lib/main.js @@ -28,7 +28,7 @@ var getOffset = require( '@stdlib/ndarray-base-offset' ); var getOrder = require( '@stdlib/ndarray-base-order' ); var getDType = require( '@stdlib/ndarray-base-dtype' ); var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -104,7 +104,7 @@ function broadcastArray( arr, shape ) { sh = getShape( arr, false ); M = sh.length; if ( N < M ) { - throw new Error( 'invalid argument. Cannot broadcast an array to a shape having fewer dimensions. Arrays can only be broadcasted to shapes having the same or more dimensions.' ); + throw new Error( format('0i50Z') ); } // Initialize a strides array... strides = []; @@ -122,7 +122,7 @@ function broadcastArray( arr, shape ) { d = sh[ j ]; dim = shape[ i ]; if ( dim !== 0 && dim < d ) { - throw new Error( format( 'invalid argument. Input array cannot be broadcast to the specified shape, as the specified shape has a dimension whose size is less than the size of the corresponding dimension in the input array. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); + throw new Error( format( '0i55F', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); } if ( d === dim ) { strides[ i ] = st[ j ]; @@ -131,7 +131,7 @@ function broadcastArray( arr, shape ) { strides[ i ] = 0; } else { // At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when "tiling" an array; e.g., `dim=4` and `d=2`)... - throw new Error( format( 'invalid argument. Input array and the specified shape are broadcast incompatible. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); + throw new Error( format( '0i55G', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); } } return ndarray( getDType( arr ), getData( arr ), copy( shape ), strides, getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len diff --git a/package.json b/package.json index 9464f21..a692769 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "@stdlib/ndarray-base-order": "^0.2.2", "@stdlib/ndarray-base-shape": "^0.2.1", "@stdlib/ndarray-base-strides": "^0.2.1", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.3.2", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, From c1f8b0fce61d74e675c842d91531f106cd1dbba4 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 29 Jul 2024 02:30:13 +0000 Subject: [PATCH 58/91] Remove files --- index.d.ts | 80 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4927 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 89664bc..0000000 --- a/index.d.ts +++ /dev/null @@ -1,80 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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. -* -* ## Notes -* -* - The function throws an error if a provided ndarray is incompatible with a provided shape. -* - The 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. -* - The returned array is a "base" ndarray, and, thus, the returned array 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 always returns a new ndarray instance even if the input ndarray shape and the desired shape are the same. -* -* @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 -* @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 = broadcastArray( 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 broadcastArray( arr: ndarray, shape: ArrayLike ): ndarray; - - -// EXPORTS // - -export = broadcastArray; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index d23160e..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 s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy-indexed@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function j(j,a){var h,p,f,l,v,b,c,g,x;if((v=a.length)<(b=(f=e(j,!1)).length))throw new Error(m("0i50Z"));for(h=[],g=0;g=0;g--)if(!((x=b-v+g)<0)){if(c=f[x],0!==(p=a[g])&&p\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction broadcastArray( arr, shape ) {\n\tvar strides;\n\tvar dim;\n\tvar sh;\n\tvar st;\n\tvar N;\n\tvar M;\n\tvar d;\n\tvar i;\n\tvar j;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\tM = sh.length;\n\tif ( N < M ) {\n\t\tthrow new Error( format('0i50Z') );\n\t}\n\t// Initialize a strides array...\n\tstrides = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tstrides.push( 0 );\n\t}\n\t// Determine the output array strides...\n\tst = getStrides( arr, false );\n\tfor ( i = N-1; i >= 0; i-- ) {\n\t\tj = M - N + i;\n\t\tif ( j < 0 ) {\n\t\t\t// Prepended singleton dimension; stride is zero...\n\t\t\tcontinue;\n\t\t}\n\t\td = sh[ j ];\n\t\tdim = shape[ i ];\n\t\tif ( dim !== 0 && dim < d ) {\n\t\t\tthrow new Error( format( '0i55F', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t\tif ( d === dim ) {\n\t\t\tstrides[ i ] = st[ j ];\n\t\t} else if ( d === 1 ) {\n\t\t\t// In order to broadcast dimensions, we set the stride for that dimension to zero...\n\t\t\tstrides[ i ] = 0;\n\t\t} else {\n\t\t\t// At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when \"tiling\" an array; e.g., `dim=4` and `d=2`)...\n\t\t\tthrow new Error( format( '0i55G', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t}\n\treturn ndarray( getDType( arr ), getData( arr ), copy( shape ), strides, getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nexport default broadcastArray;\n"],"names":["broadcastArray","arr","shape","strides","dim","sh","st","N","M","d","i","j","length","getShape","Error","format","push","getStrides","copy","join","ndarray","getDType","getData","getOffset","getOrder"],"mappings":";;s1BA2FA,SAASA,EAAgBC,EAAKC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAJ,EAAIL,EAAMU,SAEVJ,GADAH,EAAKQ,EAAUZ,GAAK,IACbW,QAEN,MAAM,IAAIE,MAAOC,EAAO,UAIzB,IADAZ,EAAU,GACJO,EAAI,EAAGA,EAAIH,EAAGG,IACnBP,EAAQa,KAAM,GAIf,IADAV,EAAKW,EAAYhB,GAAK,GAChBS,EAAIH,EAAE,EAAGG,GAAK,EAAGA,IAEtB,MADAC,EAAIH,EAAID,EAAIG,GACH,GAAT,CAMA,GAFAD,EAAIJ,EAAIM,GAEK,KADbP,EAAMF,EAAOQ,KACKN,EAAMK,EACvB,MAAM,IAAIK,MAAOC,EAAQ,QAASG,EAAMb,GAAKc,KAAM,MAAQD,EAAMhB,GAAQiB,KAAM,MAAQT,IAExF,GAAKD,IAAML,EACVD,EAASO,GAAMJ,EAAIK,OACb,IAAW,IAANF,EAKX,MAAM,IAAIK,MAAOC,EAAQ,QAASG,EAAMb,GAAKc,KAAM,MAAQD,EAAMhB,GAAQiB,KAAM,MAAQT,IAHvFP,EAASO,GAAM,CAIf,CAdA,CAgBF,OAAOU,EAASC,EAAUpB,GAAOqB,EAASrB,GAAOiB,EAAMhB,GAASC,EAASoB,EAAWtB,GAAOuB,EAAUvB,GACtG"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index b2f2533..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 07932e7378f13ecbf33897915d30e877295d6b1c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 29 Jul 2024 02:30:37 +0000 Subject: [PATCH 59/91] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 ---- .github/workflows/publish.yml | 252 -- .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 179 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 49 +- SECURITY.md | 5 - benchmark/benchmark.js | 161 - benchmark/benchmark.ndims.js | 110 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 65 - docs/types/test.ts | 94 - examples/index.js | 49 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 68 - lib/main.js | 143 - package.json | 68 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 511 --- 43 files changed, 4870 insertions(+), 4774 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 (96%) 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 6c59584..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-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 7ab66d5..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-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 e1434bb..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: '28 4 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -177,7 +168,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]. @@ -240,11 +231,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-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 d0243ca..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,161 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 broadcastArray = 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 = broadcastArray( 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', 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 = broadcastArray( 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', 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 = broadcastArray( 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(); -}); diff --git a/benchmark/benchmark.ndims.js b/benchmark/benchmark.ndims.js deleted file mode 100644 index 9530251..0000000 --- a/benchmark/benchmark.ndims.js +++ /dev/null @@ -1,110 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 broadcastArray = 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 = broadcastArray( 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 f51adca..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-array" -%% click B href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-array -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-array/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-array/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-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 a9d3107..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import broadcastArray from '../docs/types/index'; -export = broadcastArray; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 4f8387b..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var m=function(a,r){return function(){return r||a((r={exports:{}}).exports,r),r.exports}};var c=m(function(x,f){"use strict";var t=require("@stdlib/array-base-copy-indexed"),g=require("@stdlib/ndarray-base-ctor"),l=require("@stdlib/ndarray-base-shape"),y=require("@stdlib/ndarray-base-strides"),q=require("@stdlib/ndarray-base-offset"),b=require("@stdlib/ndarray-base-order"),w=require("@stdlib/ndarray-base-dtype"),D=require("@stdlib/ndarray-base-data-buffer"),p=require("@stdlib/string-format");function j(a,r){var i,o,s,v,n,u,d,e,h;if(n=r.length,s=l(a,!1),u=s.length,n=0;e--)if(h=u-n+e,!(h<0)){if(d=s[h],o=r[e],o!==0&&o\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction broadcastArray( arr, shape ) {\n\tvar strides;\n\tvar dim;\n\tvar sh;\n\tvar st;\n\tvar N;\n\tvar M;\n\tvar d;\n\tvar i;\n\tvar j;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\tM = sh.length;\n\tif ( N < M ) {\n\t\tthrow new Error( 'invalid argument. Cannot broadcast an array to a shape having fewer dimensions. Arrays can only be broadcasted to shapes having the same or more dimensions.' );\n\t}\n\t// Initialize a strides array...\n\tstrides = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tstrides.push( 0 );\n\t}\n\t// Determine the output array strides...\n\tst = getStrides( arr, false );\n\tfor ( i = N-1; i >= 0; i-- ) {\n\t\tj = M - N + i;\n\t\tif ( j < 0 ) {\n\t\t\t// Prepended singleton dimension; stride is zero...\n\t\t\tcontinue;\n\t\t}\n\t\td = sh[ j ];\n\t\tdim = shape[ i ];\n\t\tif ( dim !== 0 && dim < d ) {\n\t\t\tthrow new Error( format( 'invalid argument. Input array cannot be broadcast to the specified shape, as the specified shape has a dimension whose size is less than the size of the corresponding dimension in the input array. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t\tif ( d === dim ) {\n\t\t\tstrides[ i ] = st[ j ];\n\t\t} else if ( d === 1 ) {\n\t\t\t// In order to broadcast dimensions, we set the stride for that dimension to zero...\n\t\t\tstrides[ i ] = 0;\n\t\t} else {\n\t\t\t// At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when \"tiling\" an array; e.g., `dim=4` and `d=2`)...\n\t\t\tthrow new Error( format( 'invalid argument. Input array and the specified shape are broadcast incompatible. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t}\n\treturn ndarray( getDType( arr ), getData( arr ), copy( shape ), strides, getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nmodule.exports = broadcastArray;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast an ndarray to a specified shape.\n*\n* @module @stdlib/ndarray-base-broadcast-array\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var broadcastArray = require( '@stdlib/ndarray-base-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 = broadcastArray( 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,EAAO,QAAS,iCAAkC,EAClDC,EAAU,QAAS,2BAA4B,EAC/CC,EAAW,QAAS,4BAA6B,EACjDC,EAAa,QAAQ,8BAA+B,EACpDC,EAAY,QAAS,6BAA8B,EACnDC,EAAW,QAAS,4BAA6B,EACjDC,EAAW,QAAS,4BAA6B,EACjDC,EAAU,QAAS,kCAAmC,EACtDC,EAAS,QAAS,uBAAwB,EA6D9C,SAASC,EAAgBC,EAAKC,EAAQ,CACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACA,EACAC,EACAC,EAKJ,GAHAH,EAAIL,EAAM,OACVG,EAAKZ,EAAUQ,EAAK,EAAM,EAC1BO,EAAIH,EAAG,OACFE,EAAIC,EACR,MAAM,IAAI,MAAO,8JAA+J,EAIjL,IADAL,EAAU,CAAC,EACLM,EAAI,EAAGA,EAAIF,EAAGE,IACnBN,EAAQ,KAAM,CAAE,EAIjB,IADAG,EAAKZ,EAAYO,EAAK,EAAM,EACtBQ,EAAIF,EAAE,EAAGE,GAAK,EAAGA,IAEtB,GADAC,EAAIF,EAAID,EAAIE,EACP,EAAAC,EAAI,GAMT,IAFA,EAAIL,EAAIK,CAAE,EACVN,EAAMF,EAAOO,CAAE,EACVL,IAAQ,GAAKA,EAAM,EACvB,MAAM,IAAI,MAAOL,EAAQ,8PAA+PR,EAAMc,CAAG,EAAE,KAAM,IAAK,EAAGd,EAAMW,CAAM,EAAE,KAAM,IAAK,EAAGO,CAAE,CAAE,EAElV,GAAK,IAAML,EACVD,EAASM,CAAE,EAAIH,EAAII,CAAE,UACV,IAAM,EAEjBP,EAASM,CAAE,EAAI,MAGf,OAAM,IAAI,MAAOV,EAAQ,2IAA4IR,EAAMc,CAAG,EAAE,KAAM,IAAK,EAAGd,EAAMW,CAAM,EAAE,KAAM,IAAK,EAAGO,CAAE,CAAE,EAGhO,OAAOjB,EAASK,EAAUI,CAAI,EAAGH,EAASG,CAAI,EAAGV,EAAMW,CAAM,EAAGC,EAASR,EAAWM,CAAI,EAAGL,EAAUK,CAAI,CAAE,CAC5G,CAKAX,EAAO,QAAUU,IChFjB,IAAIW,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "copy", "ndarray", "getShape", "getStrides", "getOffset", "getOrder", "getDType", "getData", "format", "broadcastArray", "arr", "shape", "strides", "dim", "sh", "st", "N", "M", "i", "j", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index db0f44c..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,65 +0,0 @@ - -{{alias}}( arr, shape ) - Broadcasts an ndarray to a specified shape. - - The 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. - - The returned array is a "base" ndarray, and, thus, the returned array 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. - - The function always returns a new ndarray instance even if the input ndarray - shape and the desired shape are the same. - - 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 4041dc7..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,94 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 broadcastArray = 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(); - - broadcastArray( x, [ 2, 2, 2 ] ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is not provided a first argument which is an ndarray... -{ - broadcastArray( '5', [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( 5, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( true, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( false, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( null, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( {}, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( [ '5' ], [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( ( 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(); - - broadcastArray( x, '5' ); // $ExpectError - broadcastArray( x, 5 ); // $ExpectError - broadcastArray( x, true ); // $ExpectError - broadcastArray( x, false ); // $ExpectError - broadcastArray( x, null ); // $ExpectError - broadcastArray( x, {} ); // $ExpectError - broadcastArray( x, [ '5' ] ); // $ExpectError - broadcastArray( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - - broadcastArray(); // $ExpectError - broadcastArray( x ); // $ExpectError - broadcastArray( x, [ 1, 2, 3 ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index f0dc7b6..0000000 --- a/examples/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 broadcastArray = require( './../lib' ); - -// Create a 2x2 array: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -// returns - -// Broadcast the array to 3x2x2: -var y = broadcastArray( 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 sub; -var v; -var i; -for ( i = 0; i < N; i++ ) { - v = y.iget( i ); - sub = ind2sub( sh, i ); - console.log( 'Y[%s] = %d', sub.join( ', ' ), v ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index 672e358..89664bc 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..da0232c --- /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 s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy-indexed@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function j(j,a){var h,p,f,l,v,b,c,g,x;if((v=a.length)<(b=(f=e(j,!1)).length))throw new Error(m("0i50Z"));for(h=[],g=0;g=0;g--)if(!((x=b-v+g)<0)){if(c=f[x],0!==(p=a[g])&&p\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction broadcastArray( arr, shape ) {\n\tvar strides;\n\tvar dim;\n\tvar sh;\n\tvar st;\n\tvar N;\n\tvar M;\n\tvar d;\n\tvar i;\n\tvar j;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\tM = sh.length;\n\tif ( N < M ) {\n\t\tthrow new Error( format('0i50Z') );\n\t}\n\t// Initialize a strides array...\n\tstrides = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tstrides.push( 0 );\n\t}\n\t// Determine the output array strides...\n\tst = getStrides( arr, false );\n\tfor ( i = N-1; i >= 0; i-- ) {\n\t\tj = M - N + i;\n\t\tif ( j < 0 ) {\n\t\t\t// Prepended singleton dimension; stride is zero...\n\t\t\tcontinue;\n\t\t}\n\t\td = sh[ j ];\n\t\tdim = shape[ i ];\n\t\tif ( dim !== 0 && dim < d ) {\n\t\t\tthrow new Error( format( '0i55F', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t\tif ( d === dim ) {\n\t\t\tstrides[ i ] = st[ j ];\n\t\t} else if ( d === 1 ) {\n\t\t\t// In order to broadcast dimensions, we set the stride for that dimension to zero...\n\t\t\tstrides[ i ] = 0;\n\t\t} else {\n\t\t\t// At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when \"tiling\" an array; e.g., `dim=4` and `d=2`)...\n\t\t\tthrow new Error( format( '0i55G', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t}\n\treturn ndarray( getDType( arr ), getData( arr ), copy( shape ), strides, getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nexport default broadcastArray;\n"],"names":["broadcastArray","arr","shape","strides","dim","sh","st","N","M","d","i","j","length","getShape","Error","format","push","getStrides","copy","join","ndarray","getDType","getData","getOffset","getOrder"],"mappings":";;s1BA2FA,SAASA,EAAgBC,EAAKC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAJ,EAAIL,EAAMU,SAEVJ,GADAH,EAAKQ,EAAUZ,GAAK,IACbW,QAEN,MAAM,IAAIE,MAAOC,EAAO,UAIzB,IADAZ,EAAU,GACJO,EAAI,EAAGA,EAAIH,EAAGG,IACnBP,EAAQa,KAAM,GAIf,IADAV,EAAKW,EAAYhB,GAAK,GAChBS,EAAIH,EAAE,EAAGG,GAAK,EAAGA,IAEtB,MADAC,EAAIH,EAAID,EAAIG,GACH,GAAT,CAMA,GAFAD,EAAIJ,EAAIM,GAEK,KADbP,EAAMF,EAAOQ,KACKN,EAAMK,EACvB,MAAM,IAAIK,MAAOC,EAAQ,QAASG,EAAMb,GAAKc,KAAM,MAAQD,EAAMhB,GAAQiB,KAAM,MAAQT,IAExF,GAAKD,IAAML,EACVD,EAASO,GAAMJ,EAAIK,OACb,IAAW,IAANF,EAKX,MAAM,IAAIK,MAAOC,EAAQ,QAASG,EAAMb,GAAKc,KAAM,MAAQD,EAAMhB,GAAQiB,KAAM,MAAQT,IAHvFP,EAASO,GAAM,CAIf,CAdA,CAgBF,OAAOU,EAASC,EAAUpB,GAAOqB,EAASrB,GAAOiB,EAAMhB,GAASC,EAASoB,EAAWtB,GAAOuB,EAAUvB,GACtG"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index b6aaa86..0000000 --- a/lib/index.js +++ /dev/null @@ -1,68 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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. -* -* @module @stdlib/ndarray-base-broadcast-array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var broadcastArray = require( '@stdlib/ndarray-base-broadcast-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = broadcastArray( 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 3e61be9..0000000 --- a/lib/main.js +++ /dev/null @@ -1,143 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var copy = require( '@stdlib/array-base-copy-indexed' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require('@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Broadcasts an ndarray to a specified shape. -* -* ## Notes -* -* - The 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. -* -* @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 = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] ); -* // throws -*/ -function broadcastArray( arr, shape ) { - var strides; - var dim; - var sh; - var st; - var N; - var M; - var d; - var i; - var j; - - N = shape.length; - sh = getShape( arr, false ); - M = sh.length; - if ( N < M ) { - throw new Error( format('0i50Z') ); - } - // Initialize a strides array... - strides = []; - for ( i = 0; i < N; i++ ) { - strides.push( 0 ); - } - // Determine the output array strides... - st = getStrides( arr, false ); - for ( i = N-1; i >= 0; i-- ) { - j = M - N + i; - if ( j < 0 ) { - // Prepended singleton dimension; stride is zero... - continue; - } - d = sh[ j ]; - dim = shape[ i ]; - if ( dim !== 0 && dim < d ) { - throw new Error( format( '0i55F', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); - } - if ( d === dim ) { - strides[ i ] = st[ j ]; - } else if ( d === 1 ) { - // In order to broadcast dimensions, we set the stride for that dimension to zero... - strides[ i ] = 0; - } else { - // At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when "tiling" an array; e.g., `dim=4` and `d=2`)... - throw new Error( format( '0i55G', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); - } - } - return ndarray( getDType( arr ), getData( arr ), copy( shape ), strides, getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len -} - - -// EXPORTS // - -module.exports = broadcastArray; diff --git a/package.json b/package.json index a692769..5c882e8 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Broadcast an ndarray to a specified 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,46 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-copy-indexed": "^0.2.1", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/ndarray-base-data-buffer": "^0.2.2", - "@stdlib/ndarray-base-dtype": "^0.2.2", - "@stdlib/ndarray-base-offset": "^0.2.2", - "@stdlib/ndarray-base-order": "^0.2.2", - "@stdlib/ndarray-base-shape": "^0.2.1", - "@stdlib/ndarray-base-strides": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.3.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/ndarray-array": "^0.2.1", - "@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", @@ -92,7 +29,6 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..315fe2e --- /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 97decdb..0000000 --- a/test/test.js +++ /dev/null @@ -1,511 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 broadcastArray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastArray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a desired shape which has fewer dimensions than 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() { - broadcastArray( 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() { - broadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape and an input array shape 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() { - broadcastArray( x, value ); - }; - } -}); - -tape( 'the function returns a "base" ndarray instance', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = broadcastArray( 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 = broadcastArray( 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.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, 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 = broadcastArray( x, expected ); - - actual = y.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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 fe286f59868a6b766c6a85c5ceed4b6e21fe3446 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 29 Jul 2024 02:30:57 +0000 Subject: [PATCH 60/91] 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 76c35c6..6834709 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ limitations under the License. ## Usage ```javascript -import broadcastArray from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@esm/index.mjs'; +import broadcastArray from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@v0.2.2-esm/index.mjs'; ``` #### broadcastArray( arr, shape ) @@ -107,7 +107,7 @@ var y = broadcastArray( 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 broadcastArray from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@esm/index.mjs'; +import broadcastArray from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@v0.2.2-esm/index.mjs'; // Create a 2x2 array: var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); From 1f64f809465fe6cfa23921886dff2dc38dd42257 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 29 Jul 2024 02:30:57 +0000 Subject: [PATCH 61/91] Auto-generated commit --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6834709..f432b25 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,11 @@ limitations under the License. ## Usage +```javascript +import broadcastArray from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-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-broadcast-array/tags). For example, + ```javascript import broadcastArray from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@v0.2.2-esm/index.mjs'; ``` @@ -107,7 +112,7 @@ var y = broadcastArray( 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 broadcastArray from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@v0.2.2-esm/index.mjs'; +import broadcastArray from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-broadcast-array@esm/index.mjs'; // Create a 2x2 array: var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); From 647f88569cb47387c904ef5bd938b5dcb35ffa82 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Aug 2024 07:51:31 +0000 Subject: [PATCH 62/91] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index 20e9b81..3e61be9 100644 --- a/lib/main.js +++ b/lib/main.js @@ -28,7 +28,7 @@ var getOffset = require( '@stdlib/ndarray-base-offset' ); var getOrder = require( '@stdlib/ndarray-base-order' ); var getDType = require( '@stdlib/ndarray-base-dtype' ); var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -104,7 +104,7 @@ function broadcastArray( arr, shape ) { sh = getShape( arr, false ); M = sh.length; if ( N < M ) { - throw new Error( 'invalid argument. Cannot broadcast an array to a shape having fewer dimensions. Arrays can only be broadcasted to shapes having the same or more dimensions.' ); + throw new Error( format('0i50Z') ); } // Initialize a strides array... strides = []; @@ -122,7 +122,7 @@ function broadcastArray( arr, shape ) { d = sh[ j ]; dim = shape[ i ]; if ( dim !== 0 && dim < d ) { - throw new Error( format( 'invalid argument. Input array cannot be broadcast to the specified shape, as the specified shape has a dimension whose size is less than the size of the corresponding dimension in the input array. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); + throw new Error( format( '0i55F', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); } if ( d === dim ) { strides[ i ] = st[ j ]; @@ -131,7 +131,7 @@ function broadcastArray( arr, shape ) { strides[ i ] = 0; } else { // At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when "tiling" an array; e.g., `dim=4` and `d=2`)... - throw new Error( format( 'invalid argument. Input array and the specified shape are broadcast incompatible. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); + throw new Error( format( '0i55G', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); } } return ndarray( getDType( arr ), getData( arr ), copy( shape ), strides, getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len diff --git a/package.json b/package.json index 8eafcf0..b779b1d 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "@stdlib/ndarray-base-order": "^0.2.2", "@stdlib/ndarray-base-shape": "^0.2.2", "@stdlib/ndarray-base-strides": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.3.2", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, From 2e19e47e7483414570913fc2b4421f6d0687cecf Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Aug 2024 12:46:07 +0000 Subject: [PATCH 63/91] Remove files --- index.d.ts | 80 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4927 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 89664bc..0000000 --- a/index.d.ts +++ /dev/null @@ -1,80 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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. -* -* ## Notes -* -* - The function throws an error if a provided ndarray is incompatible with a provided shape. -* - The 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. -* - The returned array is a "base" ndarray, and, thus, the returned array 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 always returns a new ndarray instance even if the input ndarray shape and the desired shape are the same. -* -* @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 -* @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 = broadcastArray( 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 broadcastArray( arr: ndarray, shape: ArrayLike ): ndarray; - - -// EXPORTS // - -export = broadcastArray; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index da0232c..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 s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy-indexed@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function j(j,a){var h,p,f,l,v,b,c,g,x;if((v=a.length)<(b=(f=e(j,!1)).length))throw new Error(m("0i50Z"));for(h=[],g=0;g=0;g--)if(!((x=b-v+g)<0)){if(c=f[x],0!==(p=a[g])&&p\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction broadcastArray( arr, shape ) {\n\tvar strides;\n\tvar dim;\n\tvar sh;\n\tvar st;\n\tvar N;\n\tvar M;\n\tvar d;\n\tvar i;\n\tvar j;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\tM = sh.length;\n\tif ( N < M ) {\n\t\tthrow new Error( format('0i50Z') );\n\t}\n\t// Initialize a strides array...\n\tstrides = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tstrides.push( 0 );\n\t}\n\t// Determine the output array strides...\n\tst = getStrides( arr, false );\n\tfor ( i = N-1; i >= 0; i-- ) {\n\t\tj = M - N + i;\n\t\tif ( j < 0 ) {\n\t\t\t// Prepended singleton dimension; stride is zero...\n\t\t\tcontinue;\n\t\t}\n\t\td = sh[ j ];\n\t\tdim = shape[ i ];\n\t\tif ( dim !== 0 && dim < d ) {\n\t\t\tthrow new Error( format( '0i55F', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t\tif ( d === dim ) {\n\t\t\tstrides[ i ] = st[ j ];\n\t\t} else if ( d === 1 ) {\n\t\t\t// In order to broadcast dimensions, we set the stride for that dimension to zero...\n\t\t\tstrides[ i ] = 0;\n\t\t} else {\n\t\t\t// At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when \"tiling\" an array; e.g., `dim=4` and `d=2`)...\n\t\t\tthrow new Error( format( '0i55G', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t}\n\treturn ndarray( getDType( arr ), getData( arr ), copy( shape ), strides, getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nexport default broadcastArray;\n"],"names":["broadcastArray","arr","shape","strides","dim","sh","st","N","M","d","i","j","length","getShape","Error","format","push","getStrides","copy","join","ndarray","getDType","getData","getOffset","getOrder"],"mappings":";;s1BA2FA,SAASA,EAAgBC,EAAKC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAJ,EAAIL,EAAMU,SAEVJ,GADAH,EAAKQ,EAAUZ,GAAK,IACbW,QAEN,MAAM,IAAIE,MAAOC,EAAO,UAIzB,IADAZ,EAAU,GACJO,EAAI,EAAGA,EAAIH,EAAGG,IACnBP,EAAQa,KAAM,GAIf,IADAV,EAAKW,EAAYhB,GAAK,GAChBS,EAAIH,EAAE,EAAGG,GAAK,EAAGA,IAEtB,MADAC,EAAIH,EAAID,EAAIG,GACH,GAAT,CAMA,GAFAD,EAAIJ,EAAIM,GAEK,KADbP,EAAMF,EAAOQ,KACKN,EAAMK,EACvB,MAAM,IAAIK,MAAOC,EAAQ,QAASG,EAAMb,GAAKc,KAAM,MAAQD,EAAMhB,GAAQiB,KAAM,MAAQT,IAExF,GAAKD,IAAML,EACVD,EAASO,GAAMJ,EAAIK,OACb,IAAW,IAANF,EAKX,MAAM,IAAIK,MAAOC,EAAQ,QAASG,EAAMb,GAAKc,KAAM,MAAQD,EAAMhB,GAAQiB,KAAM,MAAQT,IAHvFP,EAASO,GAAM,CAIf,CAdA,CAgBF,OAAOU,EAASC,EAAUpB,GAAOqB,EAASrB,GAAOiB,EAAMhB,GAASC,EAASoB,EAAWtB,GAAOuB,EAAUvB,GACtG"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 315fe2e..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 6041132c22f0502e061d62b74a59706802db692d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Aug 2024 12:46:29 +0000 Subject: [PATCH 64/91] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 ---- .github/workflows/publish.yml | 252 -- .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 138 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 49 +- SECURITY.md | 5 - benchmark/benchmark.js | 161 - benchmark/benchmark.ndims.js | 110 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 65 - docs/types/test.ts | 94 - examples/index.js | 49 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 68 - lib/main.js | 143 - package.json | 68 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 511 --- 44 files changed, 4870 insertions(+), 4734 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 (96%) 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 09fa571..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-08-01T05:46:08.504Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 6c59584..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-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 7ab66d5..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-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 e1434bb..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: '28 4 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -177,7 +168,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]. @@ -240,11 +231,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-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 d0243ca..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,161 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 broadcastArray = 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 = broadcastArray( 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', 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 = broadcastArray( 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', 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 = broadcastArray( 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(); -}); diff --git a/benchmark/benchmark.ndims.js b/benchmark/benchmark.ndims.js deleted file mode 100644 index 9530251..0000000 --- a/benchmark/benchmark.ndims.js +++ /dev/null @@ -1,110 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 broadcastArray = 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 = broadcastArray( 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 f51adca..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-array" -%% click B href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-array -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-array/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-array/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-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 a9d3107..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import broadcastArray from '../docs/types/index'; -export = broadcastArray; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 4f8387b..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var m=function(a,r){return function(){return r||a((r={exports:{}}).exports,r),r.exports}};var c=m(function(x,f){"use strict";var t=require("@stdlib/array-base-copy-indexed"),g=require("@stdlib/ndarray-base-ctor"),l=require("@stdlib/ndarray-base-shape"),y=require("@stdlib/ndarray-base-strides"),q=require("@stdlib/ndarray-base-offset"),b=require("@stdlib/ndarray-base-order"),w=require("@stdlib/ndarray-base-dtype"),D=require("@stdlib/ndarray-base-data-buffer"),p=require("@stdlib/string-format");function j(a,r){var i,o,s,v,n,u,d,e,h;if(n=r.length,s=l(a,!1),u=s.length,n=0;e--)if(h=u-n+e,!(h<0)){if(d=s[h],o=r[e],o!==0&&o\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction broadcastArray( arr, shape ) {\n\tvar strides;\n\tvar dim;\n\tvar sh;\n\tvar st;\n\tvar N;\n\tvar M;\n\tvar d;\n\tvar i;\n\tvar j;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\tM = sh.length;\n\tif ( N < M ) {\n\t\tthrow new Error( 'invalid argument. Cannot broadcast an array to a shape having fewer dimensions. Arrays can only be broadcasted to shapes having the same or more dimensions.' );\n\t}\n\t// Initialize a strides array...\n\tstrides = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tstrides.push( 0 );\n\t}\n\t// Determine the output array strides...\n\tst = getStrides( arr, false );\n\tfor ( i = N-1; i >= 0; i-- ) {\n\t\tj = M - N + i;\n\t\tif ( j < 0 ) {\n\t\t\t// Prepended singleton dimension; stride is zero...\n\t\t\tcontinue;\n\t\t}\n\t\td = sh[ j ];\n\t\tdim = shape[ i ];\n\t\tif ( dim !== 0 && dim < d ) {\n\t\t\tthrow new Error( format( 'invalid argument. Input array cannot be broadcast to the specified shape, as the specified shape has a dimension whose size is less than the size of the corresponding dimension in the input array. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t\tif ( d === dim ) {\n\t\t\tstrides[ i ] = st[ j ];\n\t\t} else if ( d === 1 ) {\n\t\t\t// In order to broadcast dimensions, we set the stride for that dimension to zero...\n\t\t\tstrides[ i ] = 0;\n\t\t} else {\n\t\t\t// At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when \"tiling\" an array; e.g., `dim=4` and `d=2`)...\n\t\t\tthrow new Error( format( 'invalid argument. Input array and the specified shape are broadcast incompatible. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t}\n\treturn ndarray( getDType( arr ), getData( arr ), copy( shape ), strides, getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nmodule.exports = broadcastArray;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast an ndarray to a specified shape.\n*\n* @module @stdlib/ndarray-base-broadcast-array\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var broadcastArray = require( '@stdlib/ndarray-base-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 = broadcastArray( 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,EAAO,QAAS,iCAAkC,EAClDC,EAAU,QAAS,2BAA4B,EAC/CC,EAAW,QAAS,4BAA6B,EACjDC,EAAa,QAAQ,8BAA+B,EACpDC,EAAY,QAAS,6BAA8B,EACnDC,EAAW,QAAS,4BAA6B,EACjDC,EAAW,QAAS,4BAA6B,EACjDC,EAAU,QAAS,kCAAmC,EACtDC,EAAS,QAAS,uBAAwB,EA6D9C,SAASC,EAAgBC,EAAKC,EAAQ,CACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACA,EACAC,EACAC,EAKJ,GAHAH,EAAIL,EAAM,OACVG,EAAKZ,EAAUQ,EAAK,EAAM,EAC1BO,EAAIH,EAAG,OACFE,EAAIC,EACR,MAAM,IAAI,MAAO,8JAA+J,EAIjL,IADAL,EAAU,CAAC,EACLM,EAAI,EAAGA,EAAIF,EAAGE,IACnBN,EAAQ,KAAM,CAAE,EAIjB,IADAG,EAAKZ,EAAYO,EAAK,EAAM,EACtBQ,EAAIF,EAAE,EAAGE,GAAK,EAAGA,IAEtB,GADAC,EAAIF,EAAID,EAAIE,EACP,EAAAC,EAAI,GAMT,IAFA,EAAIL,EAAIK,CAAE,EACVN,EAAMF,EAAOO,CAAE,EACVL,IAAQ,GAAKA,EAAM,EACvB,MAAM,IAAI,MAAOL,EAAQ,8PAA+PR,EAAMc,CAAG,EAAE,KAAM,IAAK,EAAGd,EAAMW,CAAM,EAAE,KAAM,IAAK,EAAGO,CAAE,CAAE,EAElV,GAAK,IAAML,EACVD,EAASM,CAAE,EAAIH,EAAII,CAAE,UACV,IAAM,EAEjBP,EAASM,CAAE,EAAI,MAGf,OAAM,IAAI,MAAOV,EAAQ,2IAA4IR,EAAMc,CAAG,EAAE,KAAM,IAAK,EAAGd,EAAMW,CAAM,EAAE,KAAM,IAAK,EAAGO,CAAE,CAAE,EAGhO,OAAOjB,EAASK,EAAUI,CAAI,EAAGH,EAASG,CAAI,EAAGV,EAAMW,CAAM,EAAGC,EAASR,EAAWM,CAAI,EAAGL,EAAUK,CAAI,CAAE,CAC5G,CAKAX,EAAO,QAAUU,IChFjB,IAAIW,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "copy", "ndarray", "getShape", "getStrides", "getOffset", "getOrder", "getDType", "getData", "format", "broadcastArray", "arr", "shape", "strides", "dim", "sh", "st", "N", "M", "i", "j", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index db0f44c..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,65 +0,0 @@ - -{{alias}}( arr, shape ) - Broadcasts an ndarray to a specified shape. - - The 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. - - The returned array is a "base" ndarray, and, thus, the returned array 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. - - The function always returns a new ndarray instance even if the input ndarray - shape and the desired shape are the same. - - 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 4041dc7..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,94 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 broadcastArray = 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(); - - broadcastArray( x, [ 2, 2, 2 ] ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is not provided a first argument which is an ndarray... -{ - broadcastArray( '5', [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( 5, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( true, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( false, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( null, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( {}, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( [ '5' ], [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( ( 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(); - - broadcastArray( x, '5' ); // $ExpectError - broadcastArray( x, 5 ); // $ExpectError - broadcastArray( x, true ); // $ExpectError - broadcastArray( x, false ); // $ExpectError - broadcastArray( x, null ); // $ExpectError - broadcastArray( x, {} ); // $ExpectError - broadcastArray( x, [ '5' ] ); // $ExpectError - broadcastArray( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - - broadcastArray(); // $ExpectError - broadcastArray( x ); // $ExpectError - broadcastArray( x, [ 1, 2, 3 ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index f0dc7b6..0000000 --- a/examples/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 broadcastArray = require( './../lib' ); - -// Create a 2x2 array: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -// returns - -// Broadcast the array to 3x2x2: -var y = broadcastArray( 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 sub; -var v; -var i; -for ( i = 0; i < N; i++ ) { - v = y.iget( i ); - sub = ind2sub( sh, i ); - console.log( 'Y[%s] = %d', sub.join( ', ' ), v ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index 672e358..89664bc 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..da0232c --- /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 s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy-indexed@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function j(j,a){var h,p,f,l,v,b,c,g,x;if((v=a.length)<(b=(f=e(j,!1)).length))throw new Error(m("0i50Z"));for(h=[],g=0;g=0;g--)if(!((x=b-v+g)<0)){if(c=f[x],0!==(p=a[g])&&p\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction broadcastArray( arr, shape ) {\n\tvar strides;\n\tvar dim;\n\tvar sh;\n\tvar st;\n\tvar N;\n\tvar M;\n\tvar d;\n\tvar i;\n\tvar j;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\tM = sh.length;\n\tif ( N < M ) {\n\t\tthrow new Error( format('0i50Z') );\n\t}\n\t// Initialize a strides array...\n\tstrides = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tstrides.push( 0 );\n\t}\n\t// Determine the output array strides...\n\tst = getStrides( arr, false );\n\tfor ( i = N-1; i >= 0; i-- ) {\n\t\tj = M - N + i;\n\t\tif ( j < 0 ) {\n\t\t\t// Prepended singleton dimension; stride is zero...\n\t\t\tcontinue;\n\t\t}\n\t\td = sh[ j ];\n\t\tdim = shape[ i ];\n\t\tif ( dim !== 0 && dim < d ) {\n\t\t\tthrow new Error( format( '0i55F', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t\tif ( d === dim ) {\n\t\t\tstrides[ i ] = st[ j ];\n\t\t} else if ( d === 1 ) {\n\t\t\t// In order to broadcast dimensions, we set the stride for that dimension to zero...\n\t\t\tstrides[ i ] = 0;\n\t\t} else {\n\t\t\t// At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when \"tiling\" an array; e.g., `dim=4` and `d=2`)...\n\t\t\tthrow new Error( format( '0i55G', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t}\n\treturn ndarray( getDType( arr ), getData( arr ), copy( shape ), strides, getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nexport default broadcastArray;\n"],"names":["broadcastArray","arr","shape","strides","dim","sh","st","N","M","d","i","j","length","getShape","Error","format","push","getStrides","copy","join","ndarray","getDType","getData","getOffset","getOrder"],"mappings":";;s1BA2FA,SAASA,EAAgBC,EAAKC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAJ,EAAIL,EAAMU,SAEVJ,GADAH,EAAKQ,EAAUZ,GAAK,IACbW,QAEN,MAAM,IAAIE,MAAOC,EAAO,UAIzB,IADAZ,EAAU,GACJO,EAAI,EAAGA,EAAIH,EAAGG,IACnBP,EAAQa,KAAM,GAIf,IADAV,EAAKW,EAAYhB,GAAK,GAChBS,EAAIH,EAAE,EAAGG,GAAK,EAAGA,IAEtB,MADAC,EAAIH,EAAID,EAAIG,GACH,GAAT,CAMA,GAFAD,EAAIJ,EAAIM,GAEK,KADbP,EAAMF,EAAOQ,KACKN,EAAMK,EACvB,MAAM,IAAIK,MAAOC,EAAQ,QAASG,EAAMb,GAAKc,KAAM,MAAQD,EAAMhB,GAAQiB,KAAM,MAAQT,IAExF,GAAKD,IAAML,EACVD,EAASO,GAAMJ,EAAIK,OACb,IAAW,IAANF,EAKX,MAAM,IAAIK,MAAOC,EAAQ,QAASG,EAAMb,GAAKc,KAAM,MAAQD,EAAMhB,GAAQiB,KAAM,MAAQT,IAHvFP,EAASO,GAAM,CAIf,CAdA,CAgBF,OAAOU,EAASC,EAAUpB,GAAOqB,EAASrB,GAAOiB,EAAMhB,GAASC,EAASoB,EAAWtB,GAAOuB,EAAUvB,GACtG"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index b6aaa86..0000000 --- a/lib/index.js +++ /dev/null @@ -1,68 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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. -* -* @module @stdlib/ndarray-base-broadcast-array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var broadcastArray = require( '@stdlib/ndarray-base-broadcast-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = broadcastArray( 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 3e61be9..0000000 --- a/lib/main.js +++ /dev/null @@ -1,143 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var copy = require( '@stdlib/array-base-copy-indexed' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require('@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Broadcasts an ndarray to a specified shape. -* -* ## Notes -* -* - The 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. -* -* @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 = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] ); -* // throws -*/ -function broadcastArray( arr, shape ) { - var strides; - var dim; - var sh; - var st; - var N; - var M; - var d; - var i; - var j; - - N = shape.length; - sh = getShape( arr, false ); - M = sh.length; - if ( N < M ) { - throw new Error( format('0i50Z') ); - } - // Initialize a strides array... - strides = []; - for ( i = 0; i < N; i++ ) { - strides.push( 0 ); - } - // Determine the output array strides... - st = getStrides( arr, false ); - for ( i = N-1; i >= 0; i-- ) { - j = M - N + i; - if ( j < 0 ) { - // Prepended singleton dimension; stride is zero... - continue; - } - d = sh[ j ]; - dim = shape[ i ]; - if ( dim !== 0 && dim < d ) { - throw new Error( format( '0i55F', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); - } - if ( d === dim ) { - strides[ i ] = st[ j ]; - } else if ( d === 1 ) { - // In order to broadcast dimensions, we set the stride for that dimension to zero... - strides[ i ] = 0; - } else { - // At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when "tiling" an array; e.g., `dim=4` and `d=2`)... - throw new Error( format( '0i55G', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); - } - } - return ndarray( getDType( arr ), getData( arr ), copy( shape ), strides, getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len -} - - -// EXPORTS // - -module.exports = broadcastArray; diff --git a/package.json b/package.json index b779b1d..5c882e8 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Broadcast an ndarray to a specified 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,46 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-copy-indexed": "^0.2.2", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/ndarray-base-data-buffer": "^0.2.2", - "@stdlib/ndarray-base-dtype": "^0.2.2", - "@stdlib/ndarray-base-offset": "^0.2.2", - "@stdlib/ndarray-base-order": "^0.2.2", - "@stdlib/ndarray-base-shape": "^0.2.2", - "@stdlib/ndarray-base-strides": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.3.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/ndarray-array": "^0.2.1", - "@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", @@ -92,7 +29,6 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..315fe2e --- /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 97decdb..0000000 --- a/test/test.js +++ /dev/null @@ -1,511 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 broadcastArray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastArray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a desired shape which has fewer dimensions than 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() { - broadcastArray( 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() { - broadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape and an input array shape 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() { - broadcastArray( x, value ); - }; - } -}); - -tape( 'the function returns a "base" ndarray instance', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = broadcastArray( 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 = broadcastArray( 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.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, 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 = broadcastArray( x, expected ); - - actual = y.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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 0a327c5a00a2871378f65ef0cbb7c41cc569a68c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Sep 2024 08:14:56 +0000 Subject: [PATCH 65/91] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index 20e9b81..3e61be9 100644 --- a/lib/main.js +++ b/lib/main.js @@ -28,7 +28,7 @@ var getOffset = require( '@stdlib/ndarray-base-offset' ); var getOrder = require( '@stdlib/ndarray-base-order' ); var getDType = require( '@stdlib/ndarray-base-dtype' ); var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -104,7 +104,7 @@ function broadcastArray( arr, shape ) { sh = getShape( arr, false ); M = sh.length; if ( N < M ) { - throw new Error( 'invalid argument. Cannot broadcast an array to a shape having fewer dimensions. Arrays can only be broadcasted to shapes having the same or more dimensions.' ); + throw new Error( format('0i50Z') ); } // Initialize a strides array... strides = []; @@ -122,7 +122,7 @@ function broadcastArray( arr, shape ) { d = sh[ j ]; dim = shape[ i ]; if ( dim !== 0 && dim < d ) { - throw new Error( format( 'invalid argument. Input array cannot be broadcast to the specified shape, as the specified shape has a dimension whose size is less than the size of the corresponding dimension in the input array. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); + throw new Error( format( '0i55F', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); } if ( d === dim ) { strides[ i ] = st[ j ]; @@ -131,7 +131,7 @@ function broadcastArray( arr, shape ) { strides[ i ] = 0; } else { // At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when "tiling" an array; e.g., `dim=4` and `d=2`)... - throw new Error( format( 'invalid argument. Input array and the specified shape are broadcast incompatible. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); + throw new Error( format( '0i55G', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); } } return ndarray( getDType( arr ), getData( arr ), copy( shape ), strides, getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len diff --git a/package.json b/package.json index 22250bc..fdd2d13 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "@stdlib/ndarray-base-order": "^0.2.2", "@stdlib/ndarray-base-shape": "^0.2.2", "@stdlib/ndarray-base-strides": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.1", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, From 9db46f1eaf7a9f10c731f36ebe91f6219be44448 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Sep 2024 12:40:40 +0000 Subject: [PATCH 66/91] Remove files --- index.d.ts | 80 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4927 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 89664bc..0000000 --- a/index.d.ts +++ /dev/null @@ -1,80 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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. -* -* ## Notes -* -* - The function throws an error if a provided ndarray is incompatible with a provided shape. -* - The 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. -* - The returned array is a "base" ndarray, and, thus, the returned array 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 always returns a new ndarray instance even if the input ndarray shape and the desired shape are the same. -* -* @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 -* @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 = broadcastArray( 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 broadcastArray( arr: ndarray, shape: ArrayLike ): ndarray; - - -// EXPORTS // - -export = broadcastArray; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index da0232c..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 s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy-indexed@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function j(j,a){var h,p,f,l,v,b,c,g,x;if((v=a.length)<(b=(f=e(j,!1)).length))throw new Error(m("0i50Z"));for(h=[],g=0;g=0;g--)if(!((x=b-v+g)<0)){if(c=f[x],0!==(p=a[g])&&p\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction broadcastArray( arr, shape ) {\n\tvar strides;\n\tvar dim;\n\tvar sh;\n\tvar st;\n\tvar N;\n\tvar M;\n\tvar d;\n\tvar i;\n\tvar j;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\tM = sh.length;\n\tif ( N < M ) {\n\t\tthrow new Error( format('0i50Z') );\n\t}\n\t// Initialize a strides array...\n\tstrides = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tstrides.push( 0 );\n\t}\n\t// Determine the output array strides...\n\tst = getStrides( arr, false );\n\tfor ( i = N-1; i >= 0; i-- ) {\n\t\tj = M - N + i;\n\t\tif ( j < 0 ) {\n\t\t\t// Prepended singleton dimension; stride is zero...\n\t\t\tcontinue;\n\t\t}\n\t\td = sh[ j ];\n\t\tdim = shape[ i ];\n\t\tif ( dim !== 0 && dim < d ) {\n\t\t\tthrow new Error( format( '0i55F', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t\tif ( d === dim ) {\n\t\t\tstrides[ i ] = st[ j ];\n\t\t} else if ( d === 1 ) {\n\t\t\t// In order to broadcast dimensions, we set the stride for that dimension to zero...\n\t\t\tstrides[ i ] = 0;\n\t\t} else {\n\t\t\t// At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when \"tiling\" an array; e.g., `dim=4` and `d=2`)...\n\t\t\tthrow new Error( format( '0i55G', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t}\n\treturn ndarray( getDType( arr ), getData( arr ), copy( shape ), strides, getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nexport default broadcastArray;\n"],"names":["broadcastArray","arr","shape","strides","dim","sh","st","N","M","d","i","j","length","getShape","Error","format","push","getStrides","copy","join","ndarray","getDType","getData","getOffset","getOrder"],"mappings":";;s1BA2FA,SAASA,EAAgBC,EAAKC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAJ,EAAIL,EAAMU,SAEVJ,GADAH,EAAKQ,EAAUZ,GAAK,IACbW,QAEN,MAAM,IAAIE,MAAOC,EAAO,UAIzB,IADAZ,EAAU,GACJO,EAAI,EAAGA,EAAIH,EAAGG,IACnBP,EAAQa,KAAM,GAIf,IADAV,EAAKW,EAAYhB,GAAK,GAChBS,EAAIH,EAAE,EAAGG,GAAK,EAAGA,IAEtB,MADAC,EAAIH,EAAID,EAAIG,GACH,GAAT,CAMA,GAFAD,EAAIJ,EAAIM,GAEK,KADbP,EAAMF,EAAOQ,KACKN,EAAMK,EACvB,MAAM,IAAIK,MAAOC,EAAQ,QAASG,EAAMb,GAAKc,KAAM,MAAQD,EAAMhB,GAAQiB,KAAM,MAAQT,IAExF,GAAKD,IAAML,EACVD,EAASO,GAAMJ,EAAIK,OACb,IAAW,IAANF,EAKX,MAAM,IAAIK,MAAOC,EAAQ,QAASG,EAAMb,GAAKc,KAAM,MAAQD,EAAMhB,GAAQiB,KAAM,MAAQT,IAHvFP,EAASO,GAAM,CAIf,CAdA,CAgBF,OAAOU,EAASC,EAAUpB,GAAOqB,EAASrB,GAAOiB,EAAMhB,GAASC,EAASoB,EAAWtB,GAAOuB,EAAUvB,GACtG"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 315fe2e..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From bcb933328b18bacedf4b26c9ad04ed45e7fe86e9 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Sep 2024 12:41:00 +0000 Subject: [PATCH 67/91] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 ---- .github/workflows/publish.yml | 252 -- .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 178 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 49 +- SECURITY.md | 5 - benchmark/benchmark.js | 161 - benchmark/benchmark.ndims.js | 110 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 65 - docs/types/test.ts | 94 - examples/index.js | 49 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 68 - lib/main.js | 143 - package.json | 68 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 511 --- 44 files changed, 4870 insertions(+), 4774 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 (96%) 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 876d51f..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-09-01T06:12:16.942Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 6c59584..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-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 7ab66d5..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-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 e1434bb..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: '28 4 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -177,7 +168,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]. @@ -240,11 +231,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-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 d0243ca..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,161 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 broadcastArray = 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 = broadcastArray( 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', 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 = broadcastArray( 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', 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 = broadcastArray( 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(); -}); diff --git a/benchmark/benchmark.ndims.js b/benchmark/benchmark.ndims.js deleted file mode 100644 index 9530251..0000000 --- a/benchmark/benchmark.ndims.js +++ /dev/null @@ -1,110 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 broadcastArray = 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 = broadcastArray( 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 f51adca..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-array" -%% click B href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-array -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-array/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-array/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-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 a9d3107..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import broadcastArray from '../docs/types/index'; -export = broadcastArray; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 4f8387b..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var m=function(a,r){return function(){return r||a((r={exports:{}}).exports,r),r.exports}};var c=m(function(x,f){"use strict";var t=require("@stdlib/array-base-copy-indexed"),g=require("@stdlib/ndarray-base-ctor"),l=require("@stdlib/ndarray-base-shape"),y=require("@stdlib/ndarray-base-strides"),q=require("@stdlib/ndarray-base-offset"),b=require("@stdlib/ndarray-base-order"),w=require("@stdlib/ndarray-base-dtype"),D=require("@stdlib/ndarray-base-data-buffer"),p=require("@stdlib/string-format");function j(a,r){var i,o,s,v,n,u,d,e,h;if(n=r.length,s=l(a,!1),u=s.length,n=0;e--)if(h=u-n+e,!(h<0)){if(d=s[h],o=r[e],o!==0&&o\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction broadcastArray( arr, shape ) {\n\tvar strides;\n\tvar dim;\n\tvar sh;\n\tvar st;\n\tvar N;\n\tvar M;\n\tvar d;\n\tvar i;\n\tvar j;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\tM = sh.length;\n\tif ( N < M ) {\n\t\tthrow new Error( 'invalid argument. Cannot broadcast an array to a shape having fewer dimensions. Arrays can only be broadcasted to shapes having the same or more dimensions.' );\n\t}\n\t// Initialize a strides array...\n\tstrides = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tstrides.push( 0 );\n\t}\n\t// Determine the output array strides...\n\tst = getStrides( arr, false );\n\tfor ( i = N-1; i >= 0; i-- ) {\n\t\tj = M - N + i;\n\t\tif ( j < 0 ) {\n\t\t\t// Prepended singleton dimension; stride is zero...\n\t\t\tcontinue;\n\t\t}\n\t\td = sh[ j ];\n\t\tdim = shape[ i ];\n\t\tif ( dim !== 0 && dim < d ) {\n\t\t\tthrow new Error( format( 'invalid argument. Input array cannot be broadcast to the specified shape, as the specified shape has a dimension whose size is less than the size of the corresponding dimension in the input array. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t\tif ( d === dim ) {\n\t\t\tstrides[ i ] = st[ j ];\n\t\t} else if ( d === 1 ) {\n\t\t\t// In order to broadcast dimensions, we set the stride for that dimension to zero...\n\t\t\tstrides[ i ] = 0;\n\t\t} else {\n\t\t\t// At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when \"tiling\" an array; e.g., `dim=4` and `d=2`)...\n\t\t\tthrow new Error( format( 'invalid argument. Input array and the specified shape are broadcast incompatible. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t}\n\treturn ndarray( getDType( arr ), getData( arr ), copy( shape ), strides, getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nmodule.exports = broadcastArray;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast an ndarray to a specified shape.\n*\n* @module @stdlib/ndarray-base-broadcast-array\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var broadcastArray = require( '@stdlib/ndarray-base-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 = broadcastArray( 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,EAAO,QAAS,iCAAkC,EAClDC,EAAU,QAAS,2BAA4B,EAC/CC,EAAW,QAAS,4BAA6B,EACjDC,EAAa,QAAQ,8BAA+B,EACpDC,EAAY,QAAS,6BAA8B,EACnDC,EAAW,QAAS,4BAA6B,EACjDC,EAAW,QAAS,4BAA6B,EACjDC,EAAU,QAAS,kCAAmC,EACtDC,EAAS,QAAS,uBAAwB,EA6D9C,SAASC,EAAgBC,EAAKC,EAAQ,CACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACA,EACAC,EACAC,EAKJ,GAHAH,EAAIL,EAAM,OACVG,EAAKZ,EAAUQ,EAAK,EAAM,EAC1BO,EAAIH,EAAG,OACFE,EAAIC,EACR,MAAM,IAAI,MAAO,8JAA+J,EAIjL,IADAL,EAAU,CAAC,EACLM,EAAI,EAAGA,EAAIF,EAAGE,IACnBN,EAAQ,KAAM,CAAE,EAIjB,IADAG,EAAKZ,EAAYO,EAAK,EAAM,EACtBQ,EAAIF,EAAE,EAAGE,GAAK,EAAGA,IAEtB,GADAC,EAAIF,EAAID,EAAIE,EACP,EAAAC,EAAI,GAMT,IAFA,EAAIL,EAAIK,CAAE,EACVN,EAAMF,EAAOO,CAAE,EACVL,IAAQ,GAAKA,EAAM,EACvB,MAAM,IAAI,MAAOL,EAAQ,8PAA+PR,EAAMc,CAAG,EAAE,KAAM,IAAK,EAAGd,EAAMW,CAAM,EAAE,KAAM,IAAK,EAAGO,CAAE,CAAE,EAElV,GAAK,IAAML,EACVD,EAASM,CAAE,EAAIH,EAAII,CAAE,UACV,IAAM,EAEjBP,EAASM,CAAE,EAAI,MAGf,OAAM,IAAI,MAAOV,EAAQ,2IAA4IR,EAAMc,CAAG,EAAE,KAAM,IAAK,EAAGd,EAAMW,CAAM,EAAE,KAAM,IAAK,EAAGO,CAAE,CAAE,EAGhO,OAAOjB,EAASK,EAAUI,CAAI,EAAGH,EAASG,CAAI,EAAGV,EAAMW,CAAM,EAAGC,EAASR,EAAWM,CAAI,EAAGL,EAAUK,CAAI,CAAE,CAC5G,CAKAX,EAAO,QAAUU,IChFjB,IAAIW,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "copy", "ndarray", "getShape", "getStrides", "getOffset", "getOrder", "getDType", "getData", "format", "broadcastArray", "arr", "shape", "strides", "dim", "sh", "st", "N", "M", "i", "j", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index db0f44c..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,65 +0,0 @@ - -{{alias}}( arr, shape ) - Broadcasts an ndarray to a specified shape. - - The 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. - - The returned array is a "base" ndarray, and, thus, the returned array 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. - - The function always returns a new ndarray instance even if the input ndarray - shape and the desired shape are the same. - - 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 4041dc7..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,94 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 broadcastArray = 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(); - - broadcastArray( x, [ 2, 2, 2 ] ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is not provided a first argument which is an ndarray... -{ - broadcastArray( '5', [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( 5, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( true, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( false, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( null, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( {}, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( [ '5' ], [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( ( 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(); - - broadcastArray( x, '5' ); // $ExpectError - broadcastArray( x, 5 ); // $ExpectError - broadcastArray( x, true ); // $ExpectError - broadcastArray( x, false ); // $ExpectError - broadcastArray( x, null ); // $ExpectError - broadcastArray( x, {} ); // $ExpectError - broadcastArray( x, [ '5' ] ); // $ExpectError - broadcastArray( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - - broadcastArray(); // $ExpectError - broadcastArray( x ); // $ExpectError - broadcastArray( x, [ 1, 2, 3 ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index f0dc7b6..0000000 --- a/examples/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 broadcastArray = require( './../lib' ); - -// Create a 2x2 array: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -// returns - -// Broadcast the array to 3x2x2: -var y = broadcastArray( 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 sub; -var v; -var i; -for ( i = 0; i < N; i++ ) { - v = y.iget( i ); - sub = ind2sub( sh, i ); - console.log( 'Y[%s] = %d', sub.join( ', ' ), v ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index 672e358..89664bc 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..da0232c --- /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 s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy-indexed@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function j(j,a){var h,p,f,l,v,b,c,g,x;if((v=a.length)<(b=(f=e(j,!1)).length))throw new Error(m("0i50Z"));for(h=[],g=0;g=0;g--)if(!((x=b-v+g)<0)){if(c=f[x],0!==(p=a[g])&&p\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction broadcastArray( arr, shape ) {\n\tvar strides;\n\tvar dim;\n\tvar sh;\n\tvar st;\n\tvar N;\n\tvar M;\n\tvar d;\n\tvar i;\n\tvar j;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\tM = sh.length;\n\tif ( N < M ) {\n\t\tthrow new Error( format('0i50Z') );\n\t}\n\t// Initialize a strides array...\n\tstrides = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tstrides.push( 0 );\n\t}\n\t// Determine the output array strides...\n\tst = getStrides( arr, false );\n\tfor ( i = N-1; i >= 0; i-- ) {\n\t\tj = M - N + i;\n\t\tif ( j < 0 ) {\n\t\t\t// Prepended singleton dimension; stride is zero...\n\t\t\tcontinue;\n\t\t}\n\t\td = sh[ j ];\n\t\tdim = shape[ i ];\n\t\tif ( dim !== 0 && dim < d ) {\n\t\t\tthrow new Error( format( '0i55F', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t\tif ( d === dim ) {\n\t\t\tstrides[ i ] = st[ j ];\n\t\t} else if ( d === 1 ) {\n\t\t\t// In order to broadcast dimensions, we set the stride for that dimension to zero...\n\t\t\tstrides[ i ] = 0;\n\t\t} else {\n\t\t\t// At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when \"tiling\" an array; e.g., `dim=4` and `d=2`)...\n\t\t\tthrow new Error( format( '0i55G', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t}\n\treturn ndarray( getDType( arr ), getData( arr ), copy( shape ), strides, getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nexport default broadcastArray;\n"],"names":["broadcastArray","arr","shape","strides","dim","sh","st","N","M","d","i","j","length","getShape","Error","format","push","getStrides","copy","join","ndarray","getDType","getData","getOffset","getOrder"],"mappings":";;s1BA2FA,SAASA,EAAgBC,EAAKC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAJ,EAAIL,EAAMU,SAEVJ,GADAH,EAAKQ,EAAUZ,GAAK,IACbW,QAEN,MAAM,IAAIE,MAAOC,EAAO,UAIzB,IADAZ,EAAU,GACJO,EAAI,EAAGA,EAAIH,EAAGG,IACnBP,EAAQa,KAAM,GAIf,IADAV,EAAKW,EAAYhB,GAAK,GAChBS,EAAIH,EAAE,EAAGG,GAAK,EAAGA,IAEtB,MADAC,EAAIH,EAAID,EAAIG,GACH,GAAT,CAMA,GAFAD,EAAIJ,EAAIM,GAEK,KADbP,EAAMF,EAAOQ,KACKN,EAAMK,EACvB,MAAM,IAAIK,MAAOC,EAAQ,QAASG,EAAMb,GAAKc,KAAM,MAAQD,EAAMhB,GAAQiB,KAAM,MAAQT,IAExF,GAAKD,IAAML,EACVD,EAASO,GAAMJ,EAAIK,OACb,IAAW,IAANF,EAKX,MAAM,IAAIK,MAAOC,EAAQ,QAASG,EAAMb,GAAKc,KAAM,MAAQD,EAAMhB,GAAQiB,KAAM,MAAQT,IAHvFP,EAASO,GAAM,CAIf,CAdA,CAgBF,OAAOU,EAASC,EAAUpB,GAAOqB,EAASrB,GAAOiB,EAAMhB,GAASC,EAASoB,EAAWtB,GAAOuB,EAAUvB,GACtG"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index b6aaa86..0000000 --- a/lib/index.js +++ /dev/null @@ -1,68 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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. -* -* @module @stdlib/ndarray-base-broadcast-array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var broadcastArray = require( '@stdlib/ndarray-base-broadcast-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = broadcastArray( 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 3e61be9..0000000 --- a/lib/main.js +++ /dev/null @@ -1,143 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var copy = require( '@stdlib/array-base-copy-indexed' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require('@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Broadcasts an ndarray to a specified shape. -* -* ## Notes -* -* - The 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. -* -* @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 = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] ); -* // throws -*/ -function broadcastArray( arr, shape ) { - var strides; - var dim; - var sh; - var st; - var N; - var M; - var d; - var i; - var j; - - N = shape.length; - sh = getShape( arr, false ); - M = sh.length; - if ( N < M ) { - throw new Error( format('0i50Z') ); - } - // Initialize a strides array... - strides = []; - for ( i = 0; i < N; i++ ) { - strides.push( 0 ); - } - // Determine the output array strides... - st = getStrides( arr, false ); - for ( i = N-1; i >= 0; i-- ) { - j = M - N + i; - if ( j < 0 ) { - // Prepended singleton dimension; stride is zero... - continue; - } - d = sh[ j ]; - dim = shape[ i ]; - if ( dim !== 0 && dim < d ) { - throw new Error( format( '0i55F', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); - } - if ( d === dim ) { - strides[ i ] = st[ j ]; - } else if ( d === 1 ) { - // In order to broadcast dimensions, we set the stride for that dimension to zero... - strides[ i ] = 0; - } else { - // At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when "tiling" an array; e.g., `dim=4` and `d=2`)... - throw new Error( format( '0i55G', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); - } - } - return ndarray( getDType( arr ), getData( arr ), copy( shape ), strides, getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len -} - - -// EXPORTS // - -module.exports = broadcastArray; diff --git a/package.json b/package.json index fdd2d13..5c882e8 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Broadcast an ndarray to a specified 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,46 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-copy-indexed": "^0.2.2", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/ndarray-base-data-buffer": "^0.2.2", - "@stdlib/ndarray-base-dtype": "^0.2.2", - "@stdlib/ndarray-base-offset": "^0.2.2", - "@stdlib/ndarray-base-order": "^0.2.2", - "@stdlib/ndarray-base-shape": "^0.2.2", - "@stdlib/ndarray-base-strides": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/ndarray-array": "^0.2.1", - "@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", @@ -92,7 +29,6 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..315fe2e --- /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 97decdb..0000000 --- a/test/test.js +++ /dev/null @@ -1,511 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 broadcastArray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastArray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a desired shape which has fewer dimensions than 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() { - broadcastArray( 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() { - broadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape and an input array shape 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() { - broadcastArray( x, value ); - }; - } -}); - -tape( 'the function returns a "base" ndarray instance', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = broadcastArray( 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 = broadcastArray( 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.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, 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 = broadcastArray( x, expected ); - - actual = y.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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 9e5a18a98acd3c57bbcce117d0f856456ffa1230 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 24 Sep 2024 13:35:11 +0000 Subject: [PATCH 68/91] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index b4882c3..8496a36 100644 --- a/lib/main.js +++ b/lib/main.js @@ -28,7 +28,7 @@ var getOffset = require( '@stdlib/ndarray-base-offset' ); var getOrder = require( '@stdlib/ndarray-base-order' ); var getDType = require( '@stdlib/ndarray-base-dtype' ); var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -104,7 +104,7 @@ function broadcastArray( arr, shape ) { sh = getShape( arr, false ); M = sh.length; if ( N < M ) { - throw new Error( 'invalid argument. Cannot broadcast an array to a shape having fewer dimensions. Arrays can only be broadcasted to shapes having the same or more dimensions.' ); + throw new Error( format('0i50Z') ); } // Initialize a strides array... strides = []; @@ -122,7 +122,7 @@ function broadcastArray( arr, shape ) { d = sh[ j ]; dim = shape[ i ]; if ( dim !== 0 && dim < d ) { - throw new Error( format( 'invalid argument. Input array cannot be broadcast to the specified shape, as the specified shape has a dimension whose size is less than the size of the corresponding dimension in the input array. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); + throw new Error( format( '0i55F', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); } if ( d === dim ) { strides[ i ] = st[ j ]; @@ -131,7 +131,7 @@ function broadcastArray( arr, shape ) { strides[ i ] = 0; } else { // At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when "tiling" an array; e.g., `dim=4` and `d=2`)... - throw new Error( format( 'invalid argument. Input array and the specified shape are broadcast incompatible. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); + throw new Error( format( '0i55G', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); } } return ndarray( getDType( arr ), getData( arr ), copy( shape ), strides, getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len diff --git a/package.json b/package.json index 22250bc..fdd2d13 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "@stdlib/ndarray-base-order": "^0.2.2", "@stdlib/ndarray-base-shape": "^0.2.2", "@stdlib/ndarray-base-strides": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.1", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, From 9d20d26276429892ec321d2a06d0938ae5cf0a2f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 24 Sep 2024 13:40:03 +0000 Subject: [PATCH 69/91] Remove files --- index.d.ts | 80 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4927 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 89664bc..0000000 --- a/index.d.ts +++ /dev/null @@ -1,80 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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. -* -* ## Notes -* -* - The function throws an error if a provided ndarray is incompatible with a provided shape. -* - The 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. -* - The returned array is a "base" ndarray, and, thus, the returned array 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 always returns a new ndarray instance even if the input ndarray shape and the desired shape are the same. -* -* @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 -* @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 = broadcastArray( 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 broadcastArray( arr: ndarray, shape: ArrayLike ): ndarray; - - -// EXPORTS // - -export = broadcastArray; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index da0232c..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 s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy-indexed@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function j(j,a){var h,p,f,l,v,b,c,g,x;if((v=a.length)<(b=(f=e(j,!1)).length))throw new Error(m("0i50Z"));for(h=[],g=0;g=0;g--)if(!((x=b-v+g)<0)){if(c=f[x],0!==(p=a[g])&&p\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction broadcastArray( arr, shape ) {\n\tvar strides;\n\tvar dim;\n\tvar sh;\n\tvar st;\n\tvar N;\n\tvar M;\n\tvar d;\n\tvar i;\n\tvar j;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\tM = sh.length;\n\tif ( N < M ) {\n\t\tthrow new Error( format('0i50Z') );\n\t}\n\t// Initialize a strides array...\n\tstrides = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tstrides.push( 0 );\n\t}\n\t// Determine the output array strides...\n\tst = getStrides( arr, false );\n\tfor ( i = N-1; i >= 0; i-- ) {\n\t\tj = M - N + i;\n\t\tif ( j < 0 ) {\n\t\t\t// Prepended singleton dimension; stride is zero...\n\t\t\tcontinue;\n\t\t}\n\t\td = sh[ j ];\n\t\tdim = shape[ i ];\n\t\tif ( dim !== 0 && dim < d ) {\n\t\t\tthrow new Error( format( '0i55F', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t\tif ( d === dim ) {\n\t\t\tstrides[ i ] = st[ j ];\n\t\t} else if ( d === 1 ) {\n\t\t\t// In order to broadcast dimensions, we set the stride for that dimension to zero...\n\t\t\tstrides[ i ] = 0;\n\t\t} else {\n\t\t\t// At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when \"tiling\" an array; e.g., `dim=4` and `d=2`)...\n\t\t\tthrow new Error( format( '0i55G', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t}\n\treturn ndarray( getDType( arr ), getData( arr ), copy( shape ), strides, getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nexport default broadcastArray;\n"],"names":["broadcastArray","arr","shape","strides","dim","sh","st","N","M","d","i","j","length","getShape","Error","format","push","getStrides","copy","join","ndarray","getDType","getData","getOffset","getOrder"],"mappings":";;s1BA2FA,SAASA,EAAgBC,EAAKC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAJ,EAAIL,EAAMU,SAEVJ,GADAH,EAAKQ,EAAUZ,GAAK,IACbW,QAEN,MAAM,IAAIE,MAAOC,EAAO,UAIzB,IADAZ,EAAU,GACJO,EAAI,EAAGA,EAAIH,EAAGG,IACnBP,EAAQa,KAAM,GAIf,IADAV,EAAKW,EAAYhB,GAAK,GAChBS,EAAIH,EAAE,EAAGG,GAAK,EAAGA,IAEtB,MADAC,EAAIH,EAAID,EAAIG,GACH,GAAT,CAMA,GAFAD,EAAIJ,EAAIM,GAEK,KADbP,EAAMF,EAAOQ,KACKN,EAAMK,EACvB,MAAM,IAAIK,MAAOC,EAAQ,QAASG,EAAMb,GAAKc,KAAM,MAAQD,EAAMhB,GAAQiB,KAAM,MAAQT,IAExF,GAAKD,IAAML,EACVD,EAASO,GAAMJ,EAAIK,OACb,IAAW,IAANF,EAKX,MAAM,IAAIK,MAAOC,EAAQ,QAASG,EAAMb,GAAKc,KAAM,MAAQD,EAAMhB,GAAQiB,KAAM,MAAQT,IAHvFP,EAASO,GAAM,CAIf,CAdA,CAgBF,OAAOU,EAASC,EAAUpB,GAAOqB,EAASrB,GAAOiB,EAAMhB,GAASC,EAASoB,EAAWtB,GAAOuB,EAAUvB,GACtG"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 315fe2e..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 2eb84edc33e6c8e6139204035a8fcfcd716c4721 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 24 Sep 2024 13:40:32 +0000 Subject: [PATCH 70/91] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 ---- .github/workflows/publish.yml | 252 -- .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 212 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 49 +- SECURITY.md | 5 - benchmark/benchmark.js | 161 - benchmark/benchmark.ndims.js | 110 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 65 - docs/types/test.ts | 94 - examples/index.js | 49 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 68 - lib/main.js | 143 - package.json | 68 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 511 --- 43 files changed, 4870 insertions(+), 4807 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 (96%) 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 6c59584..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-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 7ab66d5..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-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 e1434bb..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: '28 4 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -177,7 +168,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]. @@ -240,11 +231,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-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 d0243ca..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,161 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 broadcastArray = 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 = broadcastArray( 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', 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 = broadcastArray( 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', 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 = broadcastArray( 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(); -}); diff --git a/benchmark/benchmark.ndims.js b/benchmark/benchmark.ndims.js deleted file mode 100644 index 9530251..0000000 --- a/benchmark/benchmark.ndims.js +++ /dev/null @@ -1,110 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 broadcastArray = 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 = broadcastArray( 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 f51adca..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-array" -%% click B href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-array -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-array/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-array/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-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 a9d3107..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import broadcastArray from '../docs/types/index'; -export = broadcastArray; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 4f8387b..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var m=function(a,r){return function(){return r||a((r={exports:{}}).exports,r),r.exports}};var c=m(function(x,f){"use strict";var t=require("@stdlib/array-base-copy-indexed"),g=require("@stdlib/ndarray-base-ctor"),l=require("@stdlib/ndarray-base-shape"),y=require("@stdlib/ndarray-base-strides"),q=require("@stdlib/ndarray-base-offset"),b=require("@stdlib/ndarray-base-order"),w=require("@stdlib/ndarray-base-dtype"),D=require("@stdlib/ndarray-base-data-buffer"),p=require("@stdlib/string-format");function j(a,r){var i,o,s,v,n,u,d,e,h;if(n=r.length,s=l(a,!1),u=s.length,n=0;e--)if(h=u-n+e,!(h<0)){if(d=s[h],o=r[e],o!==0&&o\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction broadcastArray( arr, shape ) {\n\tvar strides;\n\tvar dim;\n\tvar sh;\n\tvar st;\n\tvar N;\n\tvar M;\n\tvar d;\n\tvar i;\n\tvar j;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\tM = sh.length;\n\tif ( N < M ) {\n\t\tthrow new Error( 'invalid argument. Cannot broadcast an array to a shape having fewer dimensions. Arrays can only be broadcasted to shapes having the same or more dimensions.' );\n\t}\n\t// Initialize a strides array...\n\tstrides = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tstrides.push( 0 );\n\t}\n\t// Determine the output array strides...\n\tst = getStrides( arr, false );\n\tfor ( i = N-1; i >= 0; i-- ) {\n\t\tj = M - N + i;\n\t\tif ( j < 0 ) {\n\t\t\t// Prepended singleton dimension; stride is zero...\n\t\t\tcontinue;\n\t\t}\n\t\td = sh[ j ];\n\t\tdim = shape[ i ];\n\t\tif ( dim !== 0 && dim < d ) {\n\t\t\tthrow new Error( format( 'invalid argument. Input array cannot be broadcast to the specified shape, as the specified shape has a dimension whose size is less than the size of the corresponding dimension in the input array. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t\tif ( d === dim ) {\n\t\t\tstrides[ i ] = st[ j ];\n\t\t} else if ( d === 1 ) {\n\t\t\t// In order to broadcast dimensions, we set the stride for that dimension to zero...\n\t\t\tstrides[ i ] = 0;\n\t\t} else {\n\t\t\t// At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when \"tiling\" an array; e.g., `dim=4` and `d=2`)...\n\t\t\tthrow new Error( format( 'invalid argument. Input array and the specified shape are broadcast incompatible. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t}\n\treturn ndarray( getDType( arr ), getData( arr ), copy( shape ), strides, getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nmodule.exports = broadcastArray;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast an ndarray to a specified shape.\n*\n* @module @stdlib/ndarray-base-broadcast-array\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var broadcastArray = require( '@stdlib/ndarray-base-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 = broadcastArray( 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,EAAO,QAAS,iCAAkC,EAClDC,EAAU,QAAS,2BAA4B,EAC/CC,EAAW,QAAS,4BAA6B,EACjDC,EAAa,QAAS,8BAA+B,EACrDC,EAAY,QAAS,6BAA8B,EACnDC,EAAW,QAAS,4BAA6B,EACjDC,EAAW,QAAS,4BAA6B,EACjDC,EAAU,QAAS,kCAAmC,EACtDC,EAAS,QAAS,uBAAwB,EA6D9C,SAASC,EAAgBC,EAAKC,EAAQ,CACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACA,EACAC,EACAC,EAKJ,GAHAH,EAAIL,EAAM,OACVG,EAAKZ,EAAUQ,EAAK,EAAM,EAC1BO,EAAIH,EAAG,OACFE,EAAIC,EACR,MAAM,IAAI,MAAO,8JAA+J,EAIjL,IADAL,EAAU,CAAC,EACLM,EAAI,EAAGA,EAAIF,EAAGE,IACnBN,EAAQ,KAAM,CAAE,EAIjB,IADAG,EAAKZ,EAAYO,EAAK,EAAM,EACtBQ,EAAIF,EAAE,EAAGE,GAAK,EAAGA,IAEtB,GADAC,EAAIF,EAAID,EAAIE,EACP,EAAAC,EAAI,GAMT,IAFA,EAAIL,EAAIK,CAAE,EACVN,EAAMF,EAAOO,CAAE,EACVL,IAAQ,GAAKA,EAAM,EACvB,MAAM,IAAI,MAAOL,EAAQ,8PAA+PR,EAAMc,CAAG,EAAE,KAAM,IAAK,EAAGd,EAAMW,CAAM,EAAE,KAAM,IAAK,EAAGO,CAAE,CAAE,EAElV,GAAK,IAAML,EACVD,EAASM,CAAE,EAAIH,EAAII,CAAE,UACV,IAAM,EAEjBP,EAASM,CAAE,EAAI,MAGf,OAAM,IAAI,MAAOV,EAAQ,2IAA4IR,EAAMc,CAAG,EAAE,KAAM,IAAK,EAAGd,EAAMW,CAAM,EAAE,KAAM,IAAK,EAAGO,CAAE,CAAE,EAGhO,OAAOjB,EAASK,EAAUI,CAAI,EAAGH,EAASG,CAAI,EAAGV,EAAMW,CAAM,EAAGC,EAASR,EAAWM,CAAI,EAAGL,EAAUK,CAAI,CAAE,CAC5G,CAKAX,EAAO,QAAUU,IChFjB,IAAIW,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "copy", "ndarray", "getShape", "getStrides", "getOffset", "getOrder", "getDType", "getData", "format", "broadcastArray", "arr", "shape", "strides", "dim", "sh", "st", "N", "M", "i", "j", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index db0f44c..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,65 +0,0 @@ - -{{alias}}( arr, shape ) - Broadcasts an ndarray to a specified shape. - - The 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. - - The returned array is a "base" ndarray, and, thus, the returned array 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. - - The function always returns a new ndarray instance even if the input ndarray - shape and the desired shape are the same. - - 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 4041dc7..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,94 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 broadcastArray = 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(); - - broadcastArray( x, [ 2, 2, 2 ] ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is not provided a first argument which is an ndarray... -{ - broadcastArray( '5', [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( 5, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( true, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( false, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( null, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( {}, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( [ '5' ], [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( ( 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(); - - broadcastArray( x, '5' ); // $ExpectError - broadcastArray( x, 5 ); // $ExpectError - broadcastArray( x, true ); // $ExpectError - broadcastArray( x, false ); // $ExpectError - broadcastArray( x, null ); // $ExpectError - broadcastArray( x, {} ); // $ExpectError - broadcastArray( x, [ '5' ] ); // $ExpectError - broadcastArray( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - - broadcastArray(); // $ExpectError - broadcastArray( x ); // $ExpectError - broadcastArray( x, [ 1, 2, 3 ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index f0dc7b6..0000000 --- a/examples/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 broadcastArray = require( './../lib' ); - -// Create a 2x2 array: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -// returns - -// Broadcast the array to 3x2x2: -var y = broadcastArray( 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 sub; -var v; -var i; -for ( i = 0; i < N; i++ ) { - v = y.iget( i ); - sub = ind2sub( sh, i ); - console.log( 'Y[%s] = %d', sub.join( ', ' ), v ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index 672e358..89664bc 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..da0232c --- /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 s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy-indexed@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function j(j,a){var h,p,f,l,v,b,c,g,x;if((v=a.length)<(b=(f=e(j,!1)).length))throw new Error(m("0i50Z"));for(h=[],g=0;g=0;g--)if(!((x=b-v+g)<0)){if(c=f[x],0!==(p=a[g])&&p\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction broadcastArray( arr, shape ) {\n\tvar strides;\n\tvar dim;\n\tvar sh;\n\tvar st;\n\tvar N;\n\tvar M;\n\tvar d;\n\tvar i;\n\tvar j;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\tM = sh.length;\n\tif ( N < M ) {\n\t\tthrow new Error( format('0i50Z') );\n\t}\n\t// Initialize a strides array...\n\tstrides = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tstrides.push( 0 );\n\t}\n\t// Determine the output array strides...\n\tst = getStrides( arr, false );\n\tfor ( i = N-1; i >= 0; i-- ) {\n\t\tj = M - N + i;\n\t\tif ( j < 0 ) {\n\t\t\t// Prepended singleton dimension; stride is zero...\n\t\t\tcontinue;\n\t\t}\n\t\td = sh[ j ];\n\t\tdim = shape[ i ];\n\t\tif ( dim !== 0 && dim < d ) {\n\t\t\tthrow new Error( format( '0i55F', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t\tif ( d === dim ) {\n\t\t\tstrides[ i ] = st[ j ];\n\t\t} else if ( d === 1 ) {\n\t\t\t// In order to broadcast dimensions, we set the stride for that dimension to zero...\n\t\t\tstrides[ i ] = 0;\n\t\t} else {\n\t\t\t// At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when \"tiling\" an array; e.g., `dim=4` and `d=2`)...\n\t\t\tthrow new Error( format( '0i55G', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t}\n\treturn ndarray( getDType( arr ), getData( arr ), copy( shape ), strides, getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nexport default broadcastArray;\n"],"names":["broadcastArray","arr","shape","strides","dim","sh","st","N","M","d","i","j","length","getShape","Error","format","push","getStrides","copy","join","ndarray","getDType","getData","getOffset","getOrder"],"mappings":";;s1BA2FA,SAASA,EAAgBC,EAAKC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAJ,EAAIL,EAAMU,SAEVJ,GADAH,EAAKQ,EAAUZ,GAAK,IACbW,QAEN,MAAM,IAAIE,MAAOC,EAAO,UAIzB,IADAZ,EAAU,GACJO,EAAI,EAAGA,EAAIH,EAAGG,IACnBP,EAAQa,KAAM,GAIf,IADAV,EAAKW,EAAYhB,GAAK,GAChBS,EAAIH,EAAE,EAAGG,GAAK,EAAGA,IAEtB,MADAC,EAAIH,EAAID,EAAIG,GACH,GAAT,CAMA,GAFAD,EAAIJ,EAAIM,GAEK,KADbP,EAAMF,EAAOQ,KACKN,EAAMK,EACvB,MAAM,IAAIK,MAAOC,EAAQ,QAASG,EAAMb,GAAKc,KAAM,MAAQD,EAAMhB,GAAQiB,KAAM,MAAQT,IAExF,GAAKD,IAAML,EACVD,EAASO,GAAMJ,EAAIK,OACb,IAAW,IAANF,EAKX,MAAM,IAAIK,MAAOC,EAAQ,QAASG,EAAMb,GAAKc,KAAM,MAAQD,EAAMhB,GAAQiB,KAAM,MAAQT,IAHvFP,EAASO,GAAM,CAIf,CAdA,CAgBF,OAAOU,EAASC,EAAUpB,GAAOqB,EAASrB,GAAOiB,EAAMhB,GAASC,EAASoB,EAAWtB,GAAOuB,EAAUvB,GACtG"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index b6aaa86..0000000 --- a/lib/index.js +++ /dev/null @@ -1,68 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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. -* -* @module @stdlib/ndarray-base-broadcast-array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var broadcastArray = require( '@stdlib/ndarray-base-broadcast-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = broadcastArray( 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 8496a36..0000000 --- a/lib/main.js +++ /dev/null @@ -1,143 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var copy = require( '@stdlib/array-base-copy-indexed' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require( '@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Broadcasts an ndarray to a specified shape. -* -* ## Notes -* -* - The 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. -* -* @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 = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] ); -* // throws -*/ -function broadcastArray( arr, shape ) { - var strides; - var dim; - var sh; - var st; - var N; - var M; - var d; - var i; - var j; - - N = shape.length; - sh = getShape( arr, false ); - M = sh.length; - if ( N < M ) { - throw new Error( format('0i50Z') ); - } - // Initialize a strides array... - strides = []; - for ( i = 0; i < N; i++ ) { - strides.push( 0 ); - } - // Determine the output array strides... - st = getStrides( arr, false ); - for ( i = N-1; i >= 0; i-- ) { - j = M - N + i; - if ( j < 0 ) { - // Prepended singleton dimension; stride is zero... - continue; - } - d = sh[ j ]; - dim = shape[ i ]; - if ( dim !== 0 && dim < d ) { - throw new Error( format( '0i55F', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); - } - if ( d === dim ) { - strides[ i ] = st[ j ]; - } else if ( d === 1 ) { - // In order to broadcast dimensions, we set the stride for that dimension to zero... - strides[ i ] = 0; - } else { - // At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when "tiling" an array; e.g., `dim=4` and `d=2`)... - throw new Error( format( '0i55G', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); - } - } - return ndarray( getDType( arr ), getData( arr ), copy( shape ), strides, getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len -} - - -// EXPORTS // - -module.exports = broadcastArray; diff --git a/package.json b/package.json index fdd2d13..5c882e8 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Broadcast an ndarray to a specified 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,46 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-copy-indexed": "^0.2.2", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/ndarray-base-data-buffer": "^0.2.2", - "@stdlib/ndarray-base-dtype": "^0.2.2", - "@stdlib/ndarray-base-offset": "^0.2.2", - "@stdlib/ndarray-base-order": "^0.2.2", - "@stdlib/ndarray-base-shape": "^0.2.2", - "@stdlib/ndarray-base-strides": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/ndarray-array": "^0.2.1", - "@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", @@ -92,7 +29,6 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..315fe2e --- /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 97decdb..0000000 --- a/test/test.js +++ /dev/null @@ -1,511 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 broadcastArray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastArray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a desired shape which has fewer dimensions than 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() { - broadcastArray( 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() { - broadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape and an input array shape 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() { - broadcastArray( x, value ); - }; - } -}); - -tape( 'the function returns a "base" ndarray instance', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = broadcastArray( 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 = broadcastArray( 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.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, 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 = broadcastArray( x, expected ); - - actual = y.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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 2a331205acf0f425a97e8b84d3ffe7b33cef800b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 28 Sep 2024 21:22:00 +0000 Subject: [PATCH 71/91] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index b4882c3..8496a36 100644 --- a/lib/main.js +++ b/lib/main.js @@ -28,7 +28,7 @@ var getOffset = require( '@stdlib/ndarray-base-offset' ); var getOrder = require( '@stdlib/ndarray-base-order' ); var getDType = require( '@stdlib/ndarray-base-dtype' ); var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -104,7 +104,7 @@ function broadcastArray( arr, shape ) { sh = getShape( arr, false ); M = sh.length; if ( N < M ) { - throw new Error( 'invalid argument. Cannot broadcast an array to a shape having fewer dimensions. Arrays can only be broadcasted to shapes having the same or more dimensions.' ); + throw new Error( format('0i50Z') ); } // Initialize a strides array... strides = []; @@ -122,7 +122,7 @@ function broadcastArray( arr, shape ) { d = sh[ j ]; dim = shape[ i ]; if ( dim !== 0 && dim < d ) { - throw new Error( format( 'invalid argument. Input array cannot be broadcast to the specified shape, as the specified shape has a dimension whose size is less than the size of the corresponding dimension in the input array. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); + throw new Error( format( '0i55F', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); } if ( d === dim ) { strides[ i ] = st[ j ]; @@ -131,7 +131,7 @@ function broadcastArray( arr, shape ) { strides[ i ] = 0; } else { // At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when "tiling" an array; e.g., `dim=4` and `d=2`)... - throw new Error( format( 'invalid argument. Input array and the specified shape are broadcast incompatible. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); + throw new Error( format( '0i55G', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); } } return ndarray( getDType( arr ), getData( arr ), copy( shape ), strides, getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len diff --git a/package.json b/package.json index 22250bc..fdd2d13 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "@stdlib/ndarray-base-order": "^0.2.2", "@stdlib/ndarray-base-shape": "^0.2.2", "@stdlib/ndarray-base-strides": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.1", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, From a1528952e13ce663f7b61ec4f74017b9aefbff51 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 28 Sep 2024 21:27:15 +0000 Subject: [PATCH 72/91] Remove files --- index.d.ts | 80 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4927 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 89664bc..0000000 --- a/index.d.ts +++ /dev/null @@ -1,80 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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. -* -* ## Notes -* -* - The function throws an error if a provided ndarray is incompatible with a provided shape. -* - The 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. -* - The returned array is a "base" ndarray, and, thus, the returned array 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 always returns a new ndarray instance even if the input ndarray shape and the desired shape are the same. -* -* @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 -* @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 = broadcastArray( 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 broadcastArray( arr: ndarray, shape: ArrayLike ): ndarray; - - -// EXPORTS // - -export = broadcastArray; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index da0232c..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 s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy-indexed@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function j(j,a){var h,p,f,l,v,b,c,g,x;if((v=a.length)<(b=(f=e(j,!1)).length))throw new Error(m("0i50Z"));for(h=[],g=0;g=0;g--)if(!((x=b-v+g)<0)){if(c=f[x],0!==(p=a[g])&&p\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction broadcastArray( arr, shape ) {\n\tvar strides;\n\tvar dim;\n\tvar sh;\n\tvar st;\n\tvar N;\n\tvar M;\n\tvar d;\n\tvar i;\n\tvar j;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\tM = sh.length;\n\tif ( N < M ) {\n\t\tthrow new Error( format('0i50Z') );\n\t}\n\t// Initialize a strides array...\n\tstrides = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tstrides.push( 0 );\n\t}\n\t// Determine the output array strides...\n\tst = getStrides( arr, false );\n\tfor ( i = N-1; i >= 0; i-- ) {\n\t\tj = M - N + i;\n\t\tif ( j < 0 ) {\n\t\t\t// Prepended singleton dimension; stride is zero...\n\t\t\tcontinue;\n\t\t}\n\t\td = sh[ j ];\n\t\tdim = shape[ i ];\n\t\tif ( dim !== 0 && dim < d ) {\n\t\t\tthrow new Error( format( '0i55F', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t\tif ( d === dim ) {\n\t\t\tstrides[ i ] = st[ j ];\n\t\t} else if ( d === 1 ) {\n\t\t\t// In order to broadcast dimensions, we set the stride for that dimension to zero...\n\t\t\tstrides[ i ] = 0;\n\t\t} else {\n\t\t\t// At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when \"tiling\" an array; e.g., `dim=4` and `d=2`)...\n\t\t\tthrow new Error( format( '0i55G', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t}\n\treturn ndarray( getDType( arr ), getData( arr ), copy( shape ), strides, getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nexport default broadcastArray;\n"],"names":["broadcastArray","arr","shape","strides","dim","sh","st","N","M","d","i","j","length","getShape","Error","format","push","getStrides","copy","join","ndarray","getDType","getData","getOffset","getOrder"],"mappings":";;s1BA2FA,SAASA,EAAgBC,EAAKC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAJ,EAAIL,EAAMU,SAEVJ,GADAH,EAAKQ,EAAUZ,GAAK,IACbW,QAEN,MAAM,IAAIE,MAAOC,EAAO,UAIzB,IADAZ,EAAU,GACJO,EAAI,EAAGA,EAAIH,EAAGG,IACnBP,EAAQa,KAAM,GAIf,IADAV,EAAKW,EAAYhB,GAAK,GAChBS,EAAIH,EAAE,EAAGG,GAAK,EAAGA,IAEtB,MADAC,EAAIH,EAAID,EAAIG,GACH,GAAT,CAMA,GAFAD,EAAIJ,EAAIM,GAEK,KADbP,EAAMF,EAAOQ,KACKN,EAAMK,EACvB,MAAM,IAAIK,MAAOC,EAAQ,QAASG,EAAMb,GAAKc,KAAM,MAAQD,EAAMhB,GAAQiB,KAAM,MAAQT,IAExF,GAAKD,IAAML,EACVD,EAASO,GAAMJ,EAAIK,OACb,IAAW,IAANF,EAKX,MAAM,IAAIK,MAAOC,EAAQ,QAASG,EAAMb,GAAKc,KAAM,MAAQD,EAAMhB,GAAQiB,KAAM,MAAQT,IAHvFP,EAASO,GAAM,CAIf,CAdA,CAgBF,OAAOU,EAASC,EAAUpB,GAAOqB,EAASrB,GAAOiB,EAAMhB,GAASC,EAASoB,EAAWtB,GAAOuB,EAAUvB,GACtG"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 315fe2e..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 899948aa1346a3b0e3ff85eb57076e80221d0852 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 28 Sep 2024 21:27:36 +0000 Subject: [PATCH 73/91] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 ---- .github/workflows/publish.yml | 252 -- .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 213 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 49 +- SECURITY.md | 5 - benchmark/benchmark.js | 161 - benchmark/benchmark.ndims.js | 110 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 65 - docs/types/test.ts | 94 - examples/index.js | 49 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 68 - lib/main.js | 143 - package.json | 68 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 511 --- 43 files changed, 4870 insertions(+), 4808 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 (96%) 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 6c59584..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-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 7ab66d5..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-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 e1434bb..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: '28 4 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -177,7 +168,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]. @@ -240,11 +231,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-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 d0243ca..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,161 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 broadcastArray = 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 = broadcastArray( 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', 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 = broadcastArray( 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', 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 = broadcastArray( 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(); -}); diff --git a/benchmark/benchmark.ndims.js b/benchmark/benchmark.ndims.js deleted file mode 100644 index 9530251..0000000 --- a/benchmark/benchmark.ndims.js +++ /dev/null @@ -1,110 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 broadcastArray = 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 = broadcastArray( 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 f51adca..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-array" -%% click B href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-array -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-array/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-array/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-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 a9d3107..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import broadcastArray from '../docs/types/index'; -export = broadcastArray; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 4f8387b..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var m=function(a,r){return function(){return r||a((r={exports:{}}).exports,r),r.exports}};var c=m(function(x,f){"use strict";var t=require("@stdlib/array-base-copy-indexed"),g=require("@stdlib/ndarray-base-ctor"),l=require("@stdlib/ndarray-base-shape"),y=require("@stdlib/ndarray-base-strides"),q=require("@stdlib/ndarray-base-offset"),b=require("@stdlib/ndarray-base-order"),w=require("@stdlib/ndarray-base-dtype"),D=require("@stdlib/ndarray-base-data-buffer"),p=require("@stdlib/string-format");function j(a,r){var i,o,s,v,n,u,d,e,h;if(n=r.length,s=l(a,!1),u=s.length,n=0;e--)if(h=u-n+e,!(h<0)){if(d=s[h],o=r[e],o!==0&&o\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction broadcastArray( arr, shape ) {\n\tvar strides;\n\tvar dim;\n\tvar sh;\n\tvar st;\n\tvar N;\n\tvar M;\n\tvar d;\n\tvar i;\n\tvar j;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\tM = sh.length;\n\tif ( N < M ) {\n\t\tthrow new Error( 'invalid argument. Cannot broadcast an array to a shape having fewer dimensions. Arrays can only be broadcasted to shapes having the same or more dimensions.' );\n\t}\n\t// Initialize a strides array...\n\tstrides = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tstrides.push( 0 );\n\t}\n\t// Determine the output array strides...\n\tst = getStrides( arr, false );\n\tfor ( i = N-1; i >= 0; i-- ) {\n\t\tj = M - N + i;\n\t\tif ( j < 0 ) {\n\t\t\t// Prepended singleton dimension; stride is zero...\n\t\t\tcontinue;\n\t\t}\n\t\td = sh[ j ];\n\t\tdim = shape[ i ];\n\t\tif ( dim !== 0 && dim < d ) {\n\t\t\tthrow new Error( format( 'invalid argument. Input array cannot be broadcast to the specified shape, as the specified shape has a dimension whose size is less than the size of the corresponding dimension in the input array. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t\tif ( d === dim ) {\n\t\t\tstrides[ i ] = st[ j ];\n\t\t} else if ( d === 1 ) {\n\t\t\t// In order to broadcast dimensions, we set the stride for that dimension to zero...\n\t\t\tstrides[ i ] = 0;\n\t\t} else {\n\t\t\t// At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when \"tiling\" an array; e.g., `dim=4` and `d=2`)...\n\t\t\tthrow new Error( format( 'invalid argument. Input array and the specified shape are broadcast incompatible. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t}\n\treturn ndarray( getDType( arr ), getData( arr ), copy( shape ), strides, getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nmodule.exports = broadcastArray;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast an ndarray to a specified shape.\n*\n* @module @stdlib/ndarray-base-broadcast-array\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var broadcastArray = require( '@stdlib/ndarray-base-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 = broadcastArray( 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,EAAO,QAAS,iCAAkC,EAClDC,EAAU,QAAS,2BAA4B,EAC/CC,EAAW,QAAS,4BAA6B,EACjDC,EAAa,QAAS,8BAA+B,EACrDC,EAAY,QAAS,6BAA8B,EACnDC,EAAW,QAAS,4BAA6B,EACjDC,EAAW,QAAS,4BAA6B,EACjDC,EAAU,QAAS,kCAAmC,EACtDC,EAAS,QAAS,uBAAwB,EA6D9C,SAASC,EAAgBC,EAAKC,EAAQ,CACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACA,EACAC,EACAC,EAKJ,GAHAH,EAAIL,EAAM,OACVG,EAAKZ,EAAUQ,EAAK,EAAM,EAC1BO,EAAIH,EAAG,OACFE,EAAIC,EACR,MAAM,IAAI,MAAO,8JAA+J,EAIjL,IADAL,EAAU,CAAC,EACLM,EAAI,EAAGA,EAAIF,EAAGE,IACnBN,EAAQ,KAAM,CAAE,EAIjB,IADAG,EAAKZ,EAAYO,EAAK,EAAM,EACtBQ,EAAIF,EAAE,EAAGE,GAAK,EAAGA,IAEtB,GADAC,EAAIF,EAAID,EAAIE,EACP,EAAAC,EAAI,GAMT,IAFA,EAAIL,EAAIK,CAAE,EACVN,EAAMF,EAAOO,CAAE,EACVL,IAAQ,GAAKA,EAAM,EACvB,MAAM,IAAI,MAAOL,EAAQ,8PAA+PR,EAAMc,CAAG,EAAE,KAAM,IAAK,EAAGd,EAAMW,CAAM,EAAE,KAAM,IAAK,EAAGO,CAAE,CAAE,EAElV,GAAK,IAAML,EACVD,EAASM,CAAE,EAAIH,EAAII,CAAE,UACV,IAAM,EAEjBP,EAASM,CAAE,EAAI,MAGf,OAAM,IAAI,MAAOV,EAAQ,2IAA4IR,EAAMc,CAAG,EAAE,KAAM,IAAK,EAAGd,EAAMW,CAAM,EAAE,KAAM,IAAK,EAAGO,CAAE,CAAE,EAGhO,OAAOjB,EAASK,EAAUI,CAAI,EAAGH,EAASG,CAAI,EAAGV,EAAMW,CAAM,EAAGC,EAASR,EAAWM,CAAI,EAAGL,EAAUK,CAAI,CAAE,CAC5G,CAKAX,EAAO,QAAUU,IChFjB,IAAIW,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "copy", "ndarray", "getShape", "getStrides", "getOffset", "getOrder", "getDType", "getData", "format", "broadcastArray", "arr", "shape", "strides", "dim", "sh", "st", "N", "M", "i", "j", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index db0f44c..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,65 +0,0 @@ - -{{alias}}( arr, shape ) - Broadcasts an ndarray to a specified shape. - - The 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. - - The returned array is a "base" ndarray, and, thus, the returned array 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. - - The function always returns a new ndarray instance even if the input ndarray - shape and the desired shape are the same. - - 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 13dcd66..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,94 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 broadcastArray = 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(); - - broadcastArray( x, [ 2, 2, 2 ] ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is not provided a first argument which is an ndarray... -{ - broadcastArray( '5', [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( 5, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( true, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( false, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( null, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( {}, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( [ '5' ], [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( ( 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(); - - broadcastArray( x, '5' ); // $ExpectError - broadcastArray( x, 5 ); // $ExpectError - broadcastArray( x, true ); // $ExpectError - broadcastArray( x, false ); // $ExpectError - broadcastArray( x, null ); // $ExpectError - broadcastArray( x, {} ); // $ExpectError - broadcastArray( x, [ '5' ] ); // $ExpectError - broadcastArray( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - - broadcastArray(); // $ExpectError - broadcastArray( x ); // $ExpectError - broadcastArray( x, [ 1, 2, 3 ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index f0dc7b6..0000000 --- a/examples/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 broadcastArray = require( './../lib' ); - -// Create a 2x2 array: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -// returns - -// Broadcast the array to 3x2x2: -var y = broadcastArray( 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 sub; -var v; -var i; -for ( i = 0; i < N; i++ ) { - v = y.iget( i ); - sub = ind2sub( sh, i ); - console.log( 'Y[%s] = %d', sub.join( ', ' ), v ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index 672e358..89664bc 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..da0232c --- /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 s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy-indexed@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function j(j,a){var h,p,f,l,v,b,c,g,x;if((v=a.length)<(b=(f=e(j,!1)).length))throw new Error(m("0i50Z"));for(h=[],g=0;g=0;g--)if(!((x=b-v+g)<0)){if(c=f[x],0!==(p=a[g])&&p\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction broadcastArray( arr, shape ) {\n\tvar strides;\n\tvar dim;\n\tvar sh;\n\tvar st;\n\tvar N;\n\tvar M;\n\tvar d;\n\tvar i;\n\tvar j;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\tM = sh.length;\n\tif ( N < M ) {\n\t\tthrow new Error( format('0i50Z') );\n\t}\n\t// Initialize a strides array...\n\tstrides = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tstrides.push( 0 );\n\t}\n\t// Determine the output array strides...\n\tst = getStrides( arr, false );\n\tfor ( i = N-1; i >= 0; i-- ) {\n\t\tj = M - N + i;\n\t\tif ( j < 0 ) {\n\t\t\t// Prepended singleton dimension; stride is zero...\n\t\t\tcontinue;\n\t\t}\n\t\td = sh[ j ];\n\t\tdim = shape[ i ];\n\t\tif ( dim !== 0 && dim < d ) {\n\t\t\tthrow new Error( format( '0i55F', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t\tif ( d === dim ) {\n\t\t\tstrides[ i ] = st[ j ];\n\t\t} else if ( d === 1 ) {\n\t\t\t// In order to broadcast dimensions, we set the stride for that dimension to zero...\n\t\t\tstrides[ i ] = 0;\n\t\t} else {\n\t\t\t// At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when \"tiling\" an array; e.g., `dim=4` and `d=2`)...\n\t\t\tthrow new Error( format( '0i55G', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t}\n\treturn ndarray( getDType( arr ), getData( arr ), copy( shape ), strides, getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nexport default broadcastArray;\n"],"names":["broadcastArray","arr","shape","strides","dim","sh","st","N","M","d","i","j","length","getShape","Error","format","push","getStrides","copy","join","ndarray","getDType","getData","getOffset","getOrder"],"mappings":";;s1BA2FA,SAASA,EAAgBC,EAAKC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAJ,EAAIL,EAAMU,SAEVJ,GADAH,EAAKQ,EAAUZ,GAAK,IACbW,QAEN,MAAM,IAAIE,MAAOC,EAAO,UAIzB,IADAZ,EAAU,GACJO,EAAI,EAAGA,EAAIH,EAAGG,IACnBP,EAAQa,KAAM,GAIf,IADAV,EAAKW,EAAYhB,GAAK,GAChBS,EAAIH,EAAE,EAAGG,GAAK,EAAGA,IAEtB,MADAC,EAAIH,EAAID,EAAIG,GACH,GAAT,CAMA,GAFAD,EAAIJ,EAAIM,GAEK,KADbP,EAAMF,EAAOQ,KACKN,EAAMK,EACvB,MAAM,IAAIK,MAAOC,EAAQ,QAASG,EAAMb,GAAKc,KAAM,MAAQD,EAAMhB,GAAQiB,KAAM,MAAQT,IAExF,GAAKD,IAAML,EACVD,EAASO,GAAMJ,EAAIK,OACb,IAAW,IAANF,EAKX,MAAM,IAAIK,MAAOC,EAAQ,QAASG,EAAMb,GAAKc,KAAM,MAAQD,EAAMhB,GAAQiB,KAAM,MAAQT,IAHvFP,EAASO,GAAM,CAIf,CAdA,CAgBF,OAAOU,EAASC,EAAUpB,GAAOqB,EAASrB,GAAOiB,EAAMhB,GAASC,EAASoB,EAAWtB,GAAOuB,EAAUvB,GACtG"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index b6aaa86..0000000 --- a/lib/index.js +++ /dev/null @@ -1,68 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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. -* -* @module @stdlib/ndarray-base-broadcast-array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var broadcastArray = require( '@stdlib/ndarray-base-broadcast-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = broadcastArray( 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 8496a36..0000000 --- a/lib/main.js +++ /dev/null @@ -1,143 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var copy = require( '@stdlib/array-base-copy-indexed' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require( '@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Broadcasts an ndarray to a specified shape. -* -* ## Notes -* -* - The 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. -* -* @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 = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] ); -* // throws -*/ -function broadcastArray( arr, shape ) { - var strides; - var dim; - var sh; - var st; - var N; - var M; - var d; - var i; - var j; - - N = shape.length; - sh = getShape( arr, false ); - M = sh.length; - if ( N < M ) { - throw new Error( format('0i50Z') ); - } - // Initialize a strides array... - strides = []; - for ( i = 0; i < N; i++ ) { - strides.push( 0 ); - } - // Determine the output array strides... - st = getStrides( arr, false ); - for ( i = N-1; i >= 0; i-- ) { - j = M - N + i; - if ( j < 0 ) { - // Prepended singleton dimension; stride is zero... - continue; - } - d = sh[ j ]; - dim = shape[ i ]; - if ( dim !== 0 && dim < d ) { - throw new Error( format( '0i55F', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); - } - if ( d === dim ) { - strides[ i ] = st[ j ]; - } else if ( d === 1 ) { - // In order to broadcast dimensions, we set the stride for that dimension to zero... - strides[ i ] = 0; - } else { - // At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when "tiling" an array; e.g., `dim=4` and `d=2`)... - throw new Error( format( '0i55G', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); - } - } - return ndarray( getDType( arr ), getData( arr ), copy( shape ), strides, getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len -} - - -// EXPORTS // - -module.exports = broadcastArray; diff --git a/package.json b/package.json index fdd2d13..5c882e8 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Broadcast an ndarray to a specified 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,46 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-copy-indexed": "^0.2.2", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/ndarray-base-data-buffer": "^0.2.2", - "@stdlib/ndarray-base-dtype": "^0.2.2", - "@stdlib/ndarray-base-offset": "^0.2.2", - "@stdlib/ndarray-base-order": "^0.2.2", - "@stdlib/ndarray-base-shape": "^0.2.2", - "@stdlib/ndarray-base-strides": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/ndarray-array": "^0.2.1", - "@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", @@ -92,7 +29,6 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..315fe2e --- /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 97decdb..0000000 --- a/test/test.js +++ /dev/null @@ -1,511 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 broadcastArray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastArray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a desired shape which has fewer dimensions than 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() { - broadcastArray( 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() { - broadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape and an input array shape 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() { - broadcastArray( x, value ); - }; - } -}); - -tape( 'the function returns a "base" ndarray instance', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = broadcastArray( 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 = broadcastArray( 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.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, 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 = broadcastArray( x, expected ); - - actual = y.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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 a3daceef7f1a43fc77087e91c18cf19f9f749c50 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Oct 2024 08:31:39 +0000 Subject: [PATCH 74/91] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index b4882c3..8496a36 100644 --- a/lib/main.js +++ b/lib/main.js @@ -28,7 +28,7 @@ var getOffset = require( '@stdlib/ndarray-base-offset' ); var getOrder = require( '@stdlib/ndarray-base-order' ); var getDType = require( '@stdlib/ndarray-base-dtype' ); var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -104,7 +104,7 @@ function broadcastArray( arr, shape ) { sh = getShape( arr, false ); M = sh.length; if ( N < M ) { - throw new Error( 'invalid argument. Cannot broadcast an array to a shape having fewer dimensions. Arrays can only be broadcasted to shapes having the same or more dimensions.' ); + throw new Error( format('0i50Z') ); } // Initialize a strides array... strides = []; @@ -122,7 +122,7 @@ function broadcastArray( arr, shape ) { d = sh[ j ]; dim = shape[ i ]; if ( dim !== 0 && dim < d ) { - throw new Error( format( 'invalid argument. Input array cannot be broadcast to the specified shape, as the specified shape has a dimension whose size is less than the size of the corresponding dimension in the input array. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); + throw new Error( format( '0i55F', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); } if ( d === dim ) { strides[ i ] = st[ j ]; @@ -131,7 +131,7 @@ function broadcastArray( arr, shape ) { strides[ i ] = 0; } else { // At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when "tiling" an array; e.g., `dim=4` and `d=2`)... - throw new Error( format( 'invalid argument. Input array and the specified shape are broadcast incompatible. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); + throw new Error( format( '0i55G', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); } } return ndarray( getDType( arr ), getData( arr ), copy( shape ), strides, getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len diff --git a/package.json b/package.json index 22250bc..fdd2d13 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "@stdlib/ndarray-base-order": "^0.2.2", "@stdlib/ndarray-base-shape": "^0.2.2", "@stdlib/ndarray-base-strides": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.1", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, From abe205f9d15233e5191580450e8f242c9726e2db Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Oct 2024 13:12:21 +0000 Subject: [PATCH 75/91] Remove files --- index.d.ts | 80 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4927 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 89664bc..0000000 --- a/index.d.ts +++ /dev/null @@ -1,80 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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. -* -* ## Notes -* -* - The function throws an error if a provided ndarray is incompatible with a provided shape. -* - The 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. -* - The returned array is a "base" ndarray, and, thus, the returned array 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 always returns a new ndarray instance even if the input ndarray shape and the desired shape are the same. -* -* @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 -* @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 = broadcastArray( 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 broadcastArray( arr: ndarray, shape: ArrayLike ): ndarray; - - -// EXPORTS // - -export = broadcastArray; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index da0232c..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 s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy-indexed@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function j(j,a){var h,p,f,l,v,b,c,g,x;if((v=a.length)<(b=(f=e(j,!1)).length))throw new Error(m("0i50Z"));for(h=[],g=0;g=0;g--)if(!((x=b-v+g)<0)){if(c=f[x],0!==(p=a[g])&&p\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction broadcastArray( arr, shape ) {\n\tvar strides;\n\tvar dim;\n\tvar sh;\n\tvar st;\n\tvar N;\n\tvar M;\n\tvar d;\n\tvar i;\n\tvar j;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\tM = sh.length;\n\tif ( N < M ) {\n\t\tthrow new Error( format('0i50Z') );\n\t}\n\t// Initialize a strides array...\n\tstrides = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tstrides.push( 0 );\n\t}\n\t// Determine the output array strides...\n\tst = getStrides( arr, false );\n\tfor ( i = N-1; i >= 0; i-- ) {\n\t\tj = M - N + i;\n\t\tif ( j < 0 ) {\n\t\t\t// Prepended singleton dimension; stride is zero...\n\t\t\tcontinue;\n\t\t}\n\t\td = sh[ j ];\n\t\tdim = shape[ i ];\n\t\tif ( dim !== 0 && dim < d ) {\n\t\t\tthrow new Error( format( '0i55F', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t\tif ( d === dim ) {\n\t\t\tstrides[ i ] = st[ j ];\n\t\t} else if ( d === 1 ) {\n\t\t\t// In order to broadcast dimensions, we set the stride for that dimension to zero...\n\t\t\tstrides[ i ] = 0;\n\t\t} else {\n\t\t\t// At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when \"tiling\" an array; e.g., `dim=4` and `d=2`)...\n\t\t\tthrow new Error( format( '0i55G', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t}\n\treturn ndarray( getDType( arr ), getData( arr ), copy( shape ), strides, getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nexport default broadcastArray;\n"],"names":["broadcastArray","arr","shape","strides","dim","sh","st","N","M","d","i","j","length","getShape","Error","format","push","getStrides","copy","join","ndarray","getDType","getData","getOffset","getOrder"],"mappings":";;s1BA2FA,SAASA,EAAgBC,EAAKC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAJ,EAAIL,EAAMU,SAEVJ,GADAH,EAAKQ,EAAUZ,GAAK,IACbW,QAEN,MAAM,IAAIE,MAAOC,EAAO,UAIzB,IADAZ,EAAU,GACJO,EAAI,EAAGA,EAAIH,EAAGG,IACnBP,EAAQa,KAAM,GAIf,IADAV,EAAKW,EAAYhB,GAAK,GAChBS,EAAIH,EAAE,EAAGG,GAAK,EAAGA,IAEtB,MADAC,EAAIH,EAAID,EAAIG,GACH,GAAT,CAMA,GAFAD,EAAIJ,EAAIM,GAEK,KADbP,EAAMF,EAAOQ,KACKN,EAAMK,EACvB,MAAM,IAAIK,MAAOC,EAAQ,QAASG,EAAMb,GAAKc,KAAM,MAAQD,EAAMhB,GAAQiB,KAAM,MAAQT,IAExF,GAAKD,IAAML,EACVD,EAASO,GAAMJ,EAAIK,OACb,IAAW,IAANF,EAKX,MAAM,IAAIK,MAAOC,EAAQ,QAASG,EAAMb,GAAKc,KAAM,MAAQD,EAAMhB,GAAQiB,KAAM,MAAQT,IAHvFP,EAASO,GAAM,CAIf,CAdA,CAgBF,OAAOU,EAASC,EAAUpB,GAAOqB,EAASrB,GAAOiB,EAAMhB,GAASC,EAASoB,EAAWtB,GAAOuB,EAAUvB,GACtG"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 315fe2e..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From dadf4b3474f280e2d8a0d52485143f89e613845e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Oct 2024 13:12:50 +0000 Subject: [PATCH 76/91] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 ---- .github/workflows/publish.yml | 252 -- .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 213 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 49 +- SECURITY.md | 5 - benchmark/benchmark.js | 161 - benchmark/benchmark.ndims.js | 110 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 65 - docs/types/test.ts | 94 - examples/index.js | 49 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 68 - lib/main.js | 143 - package.json | 68 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 511 --- 44 files changed, 4870 insertions(+), 4809 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 (96%) 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 b90982e..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-10-01T06:24:30.832Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 6c59584..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-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 7ab66d5..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-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 e1434bb..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: '28 4 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -177,7 +168,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]. @@ -240,11 +231,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-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 d0243ca..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,161 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 broadcastArray = 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 = broadcastArray( 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', 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 = broadcastArray( 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', 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 = broadcastArray( 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(); -}); diff --git a/benchmark/benchmark.ndims.js b/benchmark/benchmark.ndims.js deleted file mode 100644 index 9530251..0000000 --- a/benchmark/benchmark.ndims.js +++ /dev/null @@ -1,110 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 broadcastArray = 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 = broadcastArray( 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 f51adca..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-array" -%% click B href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-array -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-array/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-array/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-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 a9d3107..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import broadcastArray from '../docs/types/index'; -export = broadcastArray; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 4f8387b..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var m=function(a,r){return function(){return r||a((r={exports:{}}).exports,r),r.exports}};var c=m(function(x,f){"use strict";var t=require("@stdlib/array-base-copy-indexed"),g=require("@stdlib/ndarray-base-ctor"),l=require("@stdlib/ndarray-base-shape"),y=require("@stdlib/ndarray-base-strides"),q=require("@stdlib/ndarray-base-offset"),b=require("@stdlib/ndarray-base-order"),w=require("@stdlib/ndarray-base-dtype"),D=require("@stdlib/ndarray-base-data-buffer"),p=require("@stdlib/string-format");function j(a,r){var i,o,s,v,n,u,d,e,h;if(n=r.length,s=l(a,!1),u=s.length,n=0;e--)if(h=u-n+e,!(h<0)){if(d=s[h],o=r[e],o!==0&&o\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction broadcastArray( arr, shape ) {\n\tvar strides;\n\tvar dim;\n\tvar sh;\n\tvar st;\n\tvar N;\n\tvar M;\n\tvar d;\n\tvar i;\n\tvar j;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\tM = sh.length;\n\tif ( N < M ) {\n\t\tthrow new Error( 'invalid argument. Cannot broadcast an array to a shape having fewer dimensions. Arrays can only be broadcasted to shapes having the same or more dimensions.' );\n\t}\n\t// Initialize a strides array...\n\tstrides = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tstrides.push( 0 );\n\t}\n\t// Determine the output array strides...\n\tst = getStrides( arr, false );\n\tfor ( i = N-1; i >= 0; i-- ) {\n\t\tj = M - N + i;\n\t\tif ( j < 0 ) {\n\t\t\t// Prepended singleton dimension; stride is zero...\n\t\t\tcontinue;\n\t\t}\n\t\td = sh[ j ];\n\t\tdim = shape[ i ];\n\t\tif ( dim !== 0 && dim < d ) {\n\t\t\tthrow new Error( format( 'invalid argument. Input array cannot be broadcast to the specified shape, as the specified shape has a dimension whose size is less than the size of the corresponding dimension in the input array. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t\tif ( d === dim ) {\n\t\t\tstrides[ i ] = st[ j ];\n\t\t} else if ( d === 1 ) {\n\t\t\t// In order to broadcast dimensions, we set the stride for that dimension to zero...\n\t\t\tstrides[ i ] = 0;\n\t\t} else {\n\t\t\t// At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when \"tiling\" an array; e.g., `dim=4` and `d=2`)...\n\t\t\tthrow new Error( format( 'invalid argument. Input array and the specified shape are broadcast incompatible. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t}\n\treturn ndarray( getDType( arr ), getData( arr ), copy( shape ), strides, getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nmodule.exports = broadcastArray;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast an ndarray to a specified shape.\n*\n* @module @stdlib/ndarray-base-broadcast-array\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var broadcastArray = require( '@stdlib/ndarray-base-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 = broadcastArray( 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,EAAO,QAAS,iCAAkC,EAClDC,EAAU,QAAS,2BAA4B,EAC/CC,EAAW,QAAS,4BAA6B,EACjDC,EAAa,QAAS,8BAA+B,EACrDC,EAAY,QAAS,6BAA8B,EACnDC,EAAW,QAAS,4BAA6B,EACjDC,EAAW,QAAS,4BAA6B,EACjDC,EAAU,QAAS,kCAAmC,EACtDC,EAAS,QAAS,uBAAwB,EA6D9C,SAASC,EAAgBC,EAAKC,EAAQ,CACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACA,EACAC,EACAC,EAKJ,GAHAH,EAAIL,EAAM,OACVG,EAAKZ,EAAUQ,EAAK,EAAM,EAC1BO,EAAIH,EAAG,OACFE,EAAIC,EACR,MAAM,IAAI,MAAO,8JAA+J,EAIjL,IADAL,EAAU,CAAC,EACLM,EAAI,EAAGA,EAAIF,EAAGE,IACnBN,EAAQ,KAAM,CAAE,EAIjB,IADAG,EAAKZ,EAAYO,EAAK,EAAM,EACtBQ,EAAIF,EAAE,EAAGE,GAAK,EAAGA,IAEtB,GADAC,EAAIF,EAAID,EAAIE,EACP,EAAAC,EAAI,GAMT,IAFA,EAAIL,EAAIK,CAAE,EACVN,EAAMF,EAAOO,CAAE,EACVL,IAAQ,GAAKA,EAAM,EACvB,MAAM,IAAI,MAAOL,EAAQ,8PAA+PR,EAAMc,CAAG,EAAE,KAAM,IAAK,EAAGd,EAAMW,CAAM,EAAE,KAAM,IAAK,EAAGO,CAAE,CAAE,EAElV,GAAK,IAAML,EACVD,EAASM,CAAE,EAAIH,EAAII,CAAE,UACV,IAAM,EAEjBP,EAASM,CAAE,EAAI,MAGf,OAAM,IAAI,MAAOV,EAAQ,2IAA4IR,EAAMc,CAAG,EAAE,KAAM,IAAK,EAAGd,EAAMW,CAAM,EAAE,KAAM,IAAK,EAAGO,CAAE,CAAE,EAGhO,OAAOjB,EAASK,EAAUI,CAAI,EAAGH,EAASG,CAAI,EAAGV,EAAMW,CAAM,EAAGC,EAASR,EAAWM,CAAI,EAAGL,EAAUK,CAAI,CAAE,CAC5G,CAKAX,EAAO,QAAUU,IChFjB,IAAIW,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "copy", "ndarray", "getShape", "getStrides", "getOffset", "getOrder", "getDType", "getData", "format", "broadcastArray", "arr", "shape", "strides", "dim", "sh", "st", "N", "M", "i", "j", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index db0f44c..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,65 +0,0 @@ - -{{alias}}( arr, shape ) - Broadcasts an ndarray to a specified shape. - - The 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. - - The returned array is a "base" ndarray, and, thus, the returned array 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. - - The function always returns a new ndarray instance even if the input ndarray - shape and the desired shape are the same. - - 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 13dcd66..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,94 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 broadcastArray = 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(); - - broadcastArray( x, [ 2, 2, 2 ] ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is not provided a first argument which is an ndarray... -{ - broadcastArray( '5', [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( 5, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( true, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( false, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( null, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( {}, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( [ '5' ], [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( ( 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(); - - broadcastArray( x, '5' ); // $ExpectError - broadcastArray( x, 5 ); // $ExpectError - broadcastArray( x, true ); // $ExpectError - broadcastArray( x, false ); // $ExpectError - broadcastArray( x, null ); // $ExpectError - broadcastArray( x, {} ); // $ExpectError - broadcastArray( x, [ '5' ] ); // $ExpectError - broadcastArray( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - - broadcastArray(); // $ExpectError - broadcastArray( x ); // $ExpectError - broadcastArray( x, [ 1, 2, 3 ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index f0dc7b6..0000000 --- a/examples/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 broadcastArray = require( './../lib' ); - -// Create a 2x2 array: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -// returns - -// Broadcast the array to 3x2x2: -var y = broadcastArray( 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 sub; -var v; -var i; -for ( i = 0; i < N; i++ ) { - v = y.iget( i ); - sub = ind2sub( sh, i ); - console.log( 'Y[%s] = %d', sub.join( ', ' ), v ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index 672e358..89664bc 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..da0232c --- /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 s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy-indexed@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function j(j,a){var h,p,f,l,v,b,c,g,x;if((v=a.length)<(b=(f=e(j,!1)).length))throw new Error(m("0i50Z"));for(h=[],g=0;g=0;g--)if(!((x=b-v+g)<0)){if(c=f[x],0!==(p=a[g])&&p\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction broadcastArray( arr, shape ) {\n\tvar strides;\n\tvar dim;\n\tvar sh;\n\tvar st;\n\tvar N;\n\tvar M;\n\tvar d;\n\tvar i;\n\tvar j;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\tM = sh.length;\n\tif ( N < M ) {\n\t\tthrow new Error( format('0i50Z') );\n\t}\n\t// Initialize a strides array...\n\tstrides = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tstrides.push( 0 );\n\t}\n\t// Determine the output array strides...\n\tst = getStrides( arr, false );\n\tfor ( i = N-1; i >= 0; i-- ) {\n\t\tj = M - N + i;\n\t\tif ( j < 0 ) {\n\t\t\t// Prepended singleton dimension; stride is zero...\n\t\t\tcontinue;\n\t\t}\n\t\td = sh[ j ];\n\t\tdim = shape[ i ];\n\t\tif ( dim !== 0 && dim < d ) {\n\t\t\tthrow new Error( format( '0i55F', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t\tif ( d === dim ) {\n\t\t\tstrides[ i ] = st[ j ];\n\t\t} else if ( d === 1 ) {\n\t\t\t// In order to broadcast dimensions, we set the stride for that dimension to zero...\n\t\t\tstrides[ i ] = 0;\n\t\t} else {\n\t\t\t// At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when \"tiling\" an array; e.g., `dim=4` and `d=2`)...\n\t\t\tthrow new Error( format( '0i55G', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t}\n\treturn ndarray( getDType( arr ), getData( arr ), copy( shape ), strides, getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nexport default broadcastArray;\n"],"names":["broadcastArray","arr","shape","strides","dim","sh","st","N","M","d","i","j","length","getShape","Error","format","push","getStrides","copy","join","ndarray","getDType","getData","getOffset","getOrder"],"mappings":";;s1BA2FA,SAASA,EAAgBC,EAAKC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAJ,EAAIL,EAAMU,SAEVJ,GADAH,EAAKQ,EAAUZ,GAAK,IACbW,QAEN,MAAM,IAAIE,MAAOC,EAAO,UAIzB,IADAZ,EAAU,GACJO,EAAI,EAAGA,EAAIH,EAAGG,IACnBP,EAAQa,KAAM,GAIf,IADAV,EAAKW,EAAYhB,GAAK,GAChBS,EAAIH,EAAE,EAAGG,GAAK,EAAGA,IAEtB,MADAC,EAAIH,EAAID,EAAIG,GACH,GAAT,CAMA,GAFAD,EAAIJ,EAAIM,GAEK,KADbP,EAAMF,EAAOQ,KACKN,EAAMK,EACvB,MAAM,IAAIK,MAAOC,EAAQ,QAASG,EAAMb,GAAKc,KAAM,MAAQD,EAAMhB,GAAQiB,KAAM,MAAQT,IAExF,GAAKD,IAAML,EACVD,EAASO,GAAMJ,EAAIK,OACb,IAAW,IAANF,EAKX,MAAM,IAAIK,MAAOC,EAAQ,QAASG,EAAMb,GAAKc,KAAM,MAAQD,EAAMhB,GAAQiB,KAAM,MAAQT,IAHvFP,EAASO,GAAM,CAIf,CAdA,CAgBF,OAAOU,EAASC,EAAUpB,GAAOqB,EAASrB,GAAOiB,EAAMhB,GAASC,EAASoB,EAAWtB,GAAOuB,EAAUvB,GACtG"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index b6aaa86..0000000 --- a/lib/index.js +++ /dev/null @@ -1,68 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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. -* -* @module @stdlib/ndarray-base-broadcast-array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var broadcastArray = require( '@stdlib/ndarray-base-broadcast-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = broadcastArray( 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 8496a36..0000000 --- a/lib/main.js +++ /dev/null @@ -1,143 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var copy = require( '@stdlib/array-base-copy-indexed' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require( '@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Broadcasts an ndarray to a specified shape. -* -* ## Notes -* -* - The 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. -* -* @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 = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] ); -* // throws -*/ -function broadcastArray( arr, shape ) { - var strides; - var dim; - var sh; - var st; - var N; - var M; - var d; - var i; - var j; - - N = shape.length; - sh = getShape( arr, false ); - M = sh.length; - if ( N < M ) { - throw new Error( format('0i50Z') ); - } - // Initialize a strides array... - strides = []; - for ( i = 0; i < N; i++ ) { - strides.push( 0 ); - } - // Determine the output array strides... - st = getStrides( arr, false ); - for ( i = N-1; i >= 0; i-- ) { - j = M - N + i; - if ( j < 0 ) { - // Prepended singleton dimension; stride is zero... - continue; - } - d = sh[ j ]; - dim = shape[ i ]; - if ( dim !== 0 && dim < d ) { - throw new Error( format( '0i55F', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); - } - if ( d === dim ) { - strides[ i ] = st[ j ]; - } else if ( d === 1 ) { - // In order to broadcast dimensions, we set the stride for that dimension to zero... - strides[ i ] = 0; - } else { - // At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when "tiling" an array; e.g., `dim=4` and `d=2`)... - throw new Error( format( '0i55G', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); - } - } - return ndarray( getDType( arr ), getData( arr ), copy( shape ), strides, getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len -} - - -// EXPORTS // - -module.exports = broadcastArray; diff --git a/package.json b/package.json index fdd2d13..5c882e8 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Broadcast an ndarray to a specified 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,46 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-copy-indexed": "^0.2.2", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/ndarray-base-data-buffer": "^0.2.2", - "@stdlib/ndarray-base-dtype": "^0.2.2", - "@stdlib/ndarray-base-offset": "^0.2.2", - "@stdlib/ndarray-base-order": "^0.2.2", - "@stdlib/ndarray-base-shape": "^0.2.2", - "@stdlib/ndarray-base-strides": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/ndarray-array": "^0.2.1", - "@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", @@ -92,7 +29,6 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..315fe2e --- /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 97decdb..0000000 --- a/test/test.js +++ /dev/null @@ -1,511 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 broadcastArray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastArray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a desired shape which has fewer dimensions than 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() { - broadcastArray( 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() { - broadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape and an input array shape 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() { - broadcastArray( x, value ); - }; - } -}); - -tape( 'the function returns a "base" ndarray instance', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = broadcastArray( 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 = broadcastArray( 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.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, 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 = broadcastArray( x, expected ); - - actual = y.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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 3c472ef06446f080e6d913468be52654f0522024 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Nov 2024 08:19:30 +0000 Subject: [PATCH 77/91] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index b4882c3..8496a36 100644 --- a/lib/main.js +++ b/lib/main.js @@ -28,7 +28,7 @@ var getOffset = require( '@stdlib/ndarray-base-offset' ); var getOrder = require( '@stdlib/ndarray-base-order' ); var getDType = require( '@stdlib/ndarray-base-dtype' ); var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -104,7 +104,7 @@ function broadcastArray( arr, shape ) { sh = getShape( arr, false ); M = sh.length; if ( N < M ) { - throw new Error( 'invalid argument. Cannot broadcast an array to a shape having fewer dimensions. Arrays can only be broadcasted to shapes having the same or more dimensions.' ); + throw new Error( format('0i50Z') ); } // Initialize a strides array... strides = []; @@ -122,7 +122,7 @@ function broadcastArray( arr, shape ) { d = sh[ j ]; dim = shape[ i ]; if ( dim !== 0 && dim < d ) { - throw new Error( format( 'invalid argument. Input array cannot be broadcast to the specified shape, as the specified shape has a dimension whose size is less than the size of the corresponding dimension in the input array. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); + throw new Error( format( '0i55F', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); } if ( d === dim ) { strides[ i ] = st[ j ]; @@ -131,7 +131,7 @@ function broadcastArray( arr, shape ) { strides[ i ] = 0; } else { // At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when "tiling" an array; e.g., `dim=4` and `d=2`)... - throw new Error( format( 'invalid argument. Input array and the specified shape are broadcast incompatible. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); + throw new Error( format( '0i55G', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); } } return ndarray( getDType( arr ), getData( arr ), copy( shape ), strides, getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len diff --git a/package.json b/package.json index 22250bc..fdd2d13 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "@stdlib/ndarray-base-order": "^0.2.2", "@stdlib/ndarray-base-shape": "^0.2.2", "@stdlib/ndarray-base-strides": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.1", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, From 0f3164341c2bbbaa762385e577be49e5d14d4157 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Nov 2024 12:18:16 +0000 Subject: [PATCH 78/91] Remove files --- index.d.ts | 80 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4927 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 89664bc..0000000 --- a/index.d.ts +++ /dev/null @@ -1,80 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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. -* -* ## Notes -* -* - The function throws an error if a provided ndarray is incompatible with a provided shape. -* - The 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. -* - The returned array is a "base" ndarray, and, thus, the returned array 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 always returns a new ndarray instance even if the input ndarray shape and the desired shape are the same. -* -* @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 -* @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 = broadcastArray( 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 broadcastArray( arr: ndarray, shape: ArrayLike ): ndarray; - - -// EXPORTS // - -export = broadcastArray; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index da0232c..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 s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy-indexed@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function j(j,a){var h,p,f,l,v,b,c,g,x;if((v=a.length)<(b=(f=e(j,!1)).length))throw new Error(m("0i50Z"));for(h=[],g=0;g=0;g--)if(!((x=b-v+g)<0)){if(c=f[x],0!==(p=a[g])&&p\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction broadcastArray( arr, shape ) {\n\tvar strides;\n\tvar dim;\n\tvar sh;\n\tvar st;\n\tvar N;\n\tvar M;\n\tvar d;\n\tvar i;\n\tvar j;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\tM = sh.length;\n\tif ( N < M ) {\n\t\tthrow new Error( format('0i50Z') );\n\t}\n\t// Initialize a strides array...\n\tstrides = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tstrides.push( 0 );\n\t}\n\t// Determine the output array strides...\n\tst = getStrides( arr, false );\n\tfor ( i = N-1; i >= 0; i-- ) {\n\t\tj = M - N + i;\n\t\tif ( j < 0 ) {\n\t\t\t// Prepended singleton dimension; stride is zero...\n\t\t\tcontinue;\n\t\t}\n\t\td = sh[ j ];\n\t\tdim = shape[ i ];\n\t\tif ( dim !== 0 && dim < d ) {\n\t\t\tthrow new Error( format( '0i55F', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t\tif ( d === dim ) {\n\t\t\tstrides[ i ] = st[ j ];\n\t\t} else if ( d === 1 ) {\n\t\t\t// In order to broadcast dimensions, we set the stride for that dimension to zero...\n\t\t\tstrides[ i ] = 0;\n\t\t} else {\n\t\t\t// At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when \"tiling\" an array; e.g., `dim=4` and `d=2`)...\n\t\t\tthrow new Error( format( '0i55G', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t}\n\treturn ndarray( getDType( arr ), getData( arr ), copy( shape ), strides, getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nexport default broadcastArray;\n"],"names":["broadcastArray","arr","shape","strides","dim","sh","st","N","M","d","i","j","length","getShape","Error","format","push","getStrides","copy","join","ndarray","getDType","getData","getOffset","getOrder"],"mappings":";;s1BA2FA,SAASA,EAAgBC,EAAKC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAJ,EAAIL,EAAMU,SAEVJ,GADAH,EAAKQ,EAAUZ,GAAK,IACbW,QAEN,MAAM,IAAIE,MAAOC,EAAO,UAIzB,IADAZ,EAAU,GACJO,EAAI,EAAGA,EAAIH,EAAGG,IACnBP,EAAQa,KAAM,GAIf,IADAV,EAAKW,EAAYhB,GAAK,GAChBS,EAAIH,EAAE,EAAGG,GAAK,EAAGA,IAEtB,MADAC,EAAIH,EAAID,EAAIG,GACH,GAAT,CAMA,GAFAD,EAAIJ,EAAIM,GAEK,KADbP,EAAMF,EAAOQ,KACKN,EAAMK,EACvB,MAAM,IAAIK,MAAOC,EAAQ,QAASG,EAAMb,GAAKc,KAAM,MAAQD,EAAMhB,GAAQiB,KAAM,MAAQT,IAExF,GAAKD,IAAML,EACVD,EAASO,GAAMJ,EAAIK,OACb,IAAW,IAANF,EAKX,MAAM,IAAIK,MAAOC,EAAQ,QAASG,EAAMb,GAAKc,KAAM,MAAQD,EAAMhB,GAAQiB,KAAM,MAAQT,IAHvFP,EAASO,GAAM,CAIf,CAdA,CAgBF,OAAOU,EAASC,EAAUpB,GAAOqB,EAASrB,GAAOiB,EAAMhB,GAASC,EAASoB,EAAWtB,GAAOuB,EAAUvB,GACtG"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 315fe2e..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From e813bbbf87fa60b6736a8a2cbeffd890045e4de6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Nov 2024 12:18:31 +0000 Subject: [PATCH 79/91] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 ---- .github/workflows/publish.yml | 252 -- .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 213 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 49 +- SECURITY.md | 5 - benchmark/benchmark.js | 161 - benchmark/benchmark.ndims.js | 110 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 65 - docs/types/test.ts | 94 - examples/index.js | 49 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 68 - lib/main.js | 143 - package.json | 68 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 511 --- 44 files changed, 4870 insertions(+), 4809 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 (96%) 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 b93658f..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-11-01T06:27:37.231Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 6c59584..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-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 7ab66d5..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-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 e1434bb..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: '28 4 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -177,7 +168,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]. @@ -240,11 +231,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-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 d0243ca..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,161 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 broadcastArray = 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 = broadcastArray( 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', 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 = broadcastArray( 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', 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 = broadcastArray( 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(); -}); diff --git a/benchmark/benchmark.ndims.js b/benchmark/benchmark.ndims.js deleted file mode 100644 index 9530251..0000000 --- a/benchmark/benchmark.ndims.js +++ /dev/null @@ -1,110 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 broadcastArray = 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 = broadcastArray( 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 f51adca..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-array" -%% click B href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-array -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-array/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-array/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-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 a9d3107..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import broadcastArray from '../docs/types/index'; -export = broadcastArray; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 4f8387b..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var m=function(a,r){return function(){return r||a((r={exports:{}}).exports,r),r.exports}};var c=m(function(x,f){"use strict";var t=require("@stdlib/array-base-copy-indexed"),g=require("@stdlib/ndarray-base-ctor"),l=require("@stdlib/ndarray-base-shape"),y=require("@stdlib/ndarray-base-strides"),q=require("@stdlib/ndarray-base-offset"),b=require("@stdlib/ndarray-base-order"),w=require("@stdlib/ndarray-base-dtype"),D=require("@stdlib/ndarray-base-data-buffer"),p=require("@stdlib/string-format");function j(a,r){var i,o,s,v,n,u,d,e,h;if(n=r.length,s=l(a,!1),u=s.length,n=0;e--)if(h=u-n+e,!(h<0)){if(d=s[h],o=r[e],o!==0&&o\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction broadcastArray( arr, shape ) {\n\tvar strides;\n\tvar dim;\n\tvar sh;\n\tvar st;\n\tvar N;\n\tvar M;\n\tvar d;\n\tvar i;\n\tvar j;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\tM = sh.length;\n\tif ( N < M ) {\n\t\tthrow new Error( 'invalid argument. Cannot broadcast an array to a shape having fewer dimensions. Arrays can only be broadcasted to shapes having the same or more dimensions.' );\n\t}\n\t// Initialize a strides array...\n\tstrides = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tstrides.push( 0 );\n\t}\n\t// Determine the output array strides...\n\tst = getStrides( arr, false );\n\tfor ( i = N-1; i >= 0; i-- ) {\n\t\tj = M - N + i;\n\t\tif ( j < 0 ) {\n\t\t\t// Prepended singleton dimension; stride is zero...\n\t\t\tcontinue;\n\t\t}\n\t\td = sh[ j ];\n\t\tdim = shape[ i ];\n\t\tif ( dim !== 0 && dim < d ) {\n\t\t\tthrow new Error( format( 'invalid argument. Input array cannot be broadcast to the specified shape, as the specified shape has a dimension whose size is less than the size of the corresponding dimension in the input array. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t\tif ( d === dim ) {\n\t\t\tstrides[ i ] = st[ j ];\n\t\t} else if ( d === 1 ) {\n\t\t\t// In order to broadcast dimensions, we set the stride for that dimension to zero...\n\t\t\tstrides[ i ] = 0;\n\t\t} else {\n\t\t\t// At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when \"tiling\" an array; e.g., `dim=4` and `d=2`)...\n\t\t\tthrow new Error( format( 'invalid argument. Input array and the specified shape are broadcast incompatible. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t}\n\treturn ndarray( getDType( arr ), getData( arr ), copy( shape ), strides, getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nmodule.exports = broadcastArray;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast an ndarray to a specified shape.\n*\n* @module @stdlib/ndarray-base-broadcast-array\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var broadcastArray = require( '@stdlib/ndarray-base-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 = broadcastArray( 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,EAAO,QAAS,iCAAkC,EAClDC,EAAU,QAAS,2BAA4B,EAC/CC,EAAW,QAAS,4BAA6B,EACjDC,EAAa,QAAS,8BAA+B,EACrDC,EAAY,QAAS,6BAA8B,EACnDC,EAAW,QAAS,4BAA6B,EACjDC,EAAW,QAAS,4BAA6B,EACjDC,EAAU,QAAS,kCAAmC,EACtDC,EAAS,QAAS,uBAAwB,EA6D9C,SAASC,EAAgBC,EAAKC,EAAQ,CACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACA,EACAC,EACAC,EAKJ,GAHAH,EAAIL,EAAM,OACVG,EAAKZ,EAAUQ,EAAK,EAAM,EAC1BO,EAAIH,EAAG,OACFE,EAAIC,EACR,MAAM,IAAI,MAAO,8JAA+J,EAIjL,IADAL,EAAU,CAAC,EACLM,EAAI,EAAGA,EAAIF,EAAGE,IACnBN,EAAQ,KAAM,CAAE,EAIjB,IADAG,EAAKZ,EAAYO,EAAK,EAAM,EACtBQ,EAAIF,EAAE,EAAGE,GAAK,EAAGA,IAEtB,GADAC,EAAIF,EAAID,EAAIE,EACP,EAAAC,EAAI,GAMT,IAFA,EAAIL,EAAIK,CAAE,EACVN,EAAMF,EAAOO,CAAE,EACVL,IAAQ,GAAKA,EAAM,EACvB,MAAM,IAAI,MAAOL,EAAQ,8PAA+PR,EAAMc,CAAG,EAAE,KAAM,IAAK,EAAGd,EAAMW,CAAM,EAAE,KAAM,IAAK,EAAGO,CAAE,CAAE,EAElV,GAAK,IAAML,EACVD,EAASM,CAAE,EAAIH,EAAII,CAAE,UACV,IAAM,EAEjBP,EAASM,CAAE,EAAI,MAGf,OAAM,IAAI,MAAOV,EAAQ,2IAA4IR,EAAMc,CAAG,EAAE,KAAM,IAAK,EAAGd,EAAMW,CAAM,EAAE,KAAM,IAAK,EAAGO,CAAE,CAAE,EAGhO,OAAOjB,EAASK,EAAUI,CAAI,EAAGH,EAASG,CAAI,EAAGV,EAAMW,CAAM,EAAGC,EAASR,EAAWM,CAAI,EAAGL,EAAUK,CAAI,CAAE,CAC5G,CAKAX,EAAO,QAAUU,IChFjB,IAAIW,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "copy", "ndarray", "getShape", "getStrides", "getOffset", "getOrder", "getDType", "getData", "format", "broadcastArray", "arr", "shape", "strides", "dim", "sh", "st", "N", "M", "i", "j", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index db0f44c..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,65 +0,0 @@ - -{{alias}}( arr, shape ) - Broadcasts an ndarray to a specified shape. - - The 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. - - The returned array is a "base" ndarray, and, thus, the returned array 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. - - The function always returns a new ndarray instance even if the input ndarray - shape and the desired shape are the same. - - 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 13dcd66..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,94 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 broadcastArray = 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(); - - broadcastArray( x, [ 2, 2, 2 ] ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is not provided a first argument which is an ndarray... -{ - broadcastArray( '5', [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( 5, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( true, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( false, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( null, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( {}, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( [ '5' ], [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( ( 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(); - - broadcastArray( x, '5' ); // $ExpectError - broadcastArray( x, 5 ); // $ExpectError - broadcastArray( x, true ); // $ExpectError - broadcastArray( x, false ); // $ExpectError - broadcastArray( x, null ); // $ExpectError - broadcastArray( x, {} ); // $ExpectError - broadcastArray( x, [ '5' ] ); // $ExpectError - broadcastArray( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - - broadcastArray(); // $ExpectError - broadcastArray( x ); // $ExpectError - broadcastArray( x, [ 1, 2, 3 ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index f0dc7b6..0000000 --- a/examples/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 broadcastArray = require( './../lib' ); - -// Create a 2x2 array: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -// returns - -// Broadcast the array to 3x2x2: -var y = broadcastArray( 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 sub; -var v; -var i; -for ( i = 0; i < N; i++ ) { - v = y.iget( i ); - sub = ind2sub( sh, i ); - console.log( 'Y[%s] = %d', sub.join( ', ' ), v ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index 672e358..89664bc 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..da0232c --- /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 s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy-indexed@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function j(j,a){var h,p,f,l,v,b,c,g,x;if((v=a.length)<(b=(f=e(j,!1)).length))throw new Error(m("0i50Z"));for(h=[],g=0;g=0;g--)if(!((x=b-v+g)<0)){if(c=f[x],0!==(p=a[g])&&p\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction broadcastArray( arr, shape ) {\n\tvar strides;\n\tvar dim;\n\tvar sh;\n\tvar st;\n\tvar N;\n\tvar M;\n\tvar d;\n\tvar i;\n\tvar j;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\tM = sh.length;\n\tif ( N < M ) {\n\t\tthrow new Error( format('0i50Z') );\n\t}\n\t// Initialize a strides array...\n\tstrides = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tstrides.push( 0 );\n\t}\n\t// Determine the output array strides...\n\tst = getStrides( arr, false );\n\tfor ( i = N-1; i >= 0; i-- ) {\n\t\tj = M - N + i;\n\t\tif ( j < 0 ) {\n\t\t\t// Prepended singleton dimension; stride is zero...\n\t\t\tcontinue;\n\t\t}\n\t\td = sh[ j ];\n\t\tdim = shape[ i ];\n\t\tif ( dim !== 0 && dim < d ) {\n\t\t\tthrow new Error( format( '0i55F', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t\tif ( d === dim ) {\n\t\t\tstrides[ i ] = st[ j ];\n\t\t} else if ( d === 1 ) {\n\t\t\t// In order to broadcast dimensions, we set the stride for that dimension to zero...\n\t\t\tstrides[ i ] = 0;\n\t\t} else {\n\t\t\t// At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when \"tiling\" an array; e.g., `dim=4` and `d=2`)...\n\t\t\tthrow new Error( format( '0i55G', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t}\n\treturn ndarray( getDType( arr ), getData( arr ), copy( shape ), strides, getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nexport default broadcastArray;\n"],"names":["broadcastArray","arr","shape","strides","dim","sh","st","N","M","d","i","j","length","getShape","Error","format","push","getStrides","copy","join","ndarray","getDType","getData","getOffset","getOrder"],"mappings":";;s1BA2FA,SAASA,EAAgBC,EAAKC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAJ,EAAIL,EAAMU,SAEVJ,GADAH,EAAKQ,EAAUZ,GAAK,IACbW,QAEN,MAAM,IAAIE,MAAOC,EAAO,UAIzB,IADAZ,EAAU,GACJO,EAAI,EAAGA,EAAIH,EAAGG,IACnBP,EAAQa,KAAM,GAIf,IADAV,EAAKW,EAAYhB,GAAK,GAChBS,EAAIH,EAAE,EAAGG,GAAK,EAAGA,IAEtB,MADAC,EAAIH,EAAID,EAAIG,GACH,GAAT,CAMA,GAFAD,EAAIJ,EAAIM,GAEK,KADbP,EAAMF,EAAOQ,KACKN,EAAMK,EACvB,MAAM,IAAIK,MAAOC,EAAQ,QAASG,EAAMb,GAAKc,KAAM,MAAQD,EAAMhB,GAAQiB,KAAM,MAAQT,IAExF,GAAKD,IAAML,EACVD,EAASO,GAAMJ,EAAIK,OACb,IAAW,IAANF,EAKX,MAAM,IAAIK,MAAOC,EAAQ,QAASG,EAAMb,GAAKc,KAAM,MAAQD,EAAMhB,GAAQiB,KAAM,MAAQT,IAHvFP,EAASO,GAAM,CAIf,CAdA,CAgBF,OAAOU,EAASC,EAAUpB,GAAOqB,EAASrB,GAAOiB,EAAMhB,GAASC,EAASoB,EAAWtB,GAAOuB,EAAUvB,GACtG"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index b6aaa86..0000000 --- a/lib/index.js +++ /dev/null @@ -1,68 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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. -* -* @module @stdlib/ndarray-base-broadcast-array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var broadcastArray = require( '@stdlib/ndarray-base-broadcast-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = broadcastArray( 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 8496a36..0000000 --- a/lib/main.js +++ /dev/null @@ -1,143 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var copy = require( '@stdlib/array-base-copy-indexed' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require( '@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Broadcasts an ndarray to a specified shape. -* -* ## Notes -* -* - The 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. -* -* @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 = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] ); -* // throws -*/ -function broadcastArray( arr, shape ) { - var strides; - var dim; - var sh; - var st; - var N; - var M; - var d; - var i; - var j; - - N = shape.length; - sh = getShape( arr, false ); - M = sh.length; - if ( N < M ) { - throw new Error( format('0i50Z') ); - } - // Initialize a strides array... - strides = []; - for ( i = 0; i < N; i++ ) { - strides.push( 0 ); - } - // Determine the output array strides... - st = getStrides( arr, false ); - for ( i = N-1; i >= 0; i-- ) { - j = M - N + i; - if ( j < 0 ) { - // Prepended singleton dimension; stride is zero... - continue; - } - d = sh[ j ]; - dim = shape[ i ]; - if ( dim !== 0 && dim < d ) { - throw new Error( format( '0i55F', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); - } - if ( d === dim ) { - strides[ i ] = st[ j ]; - } else if ( d === 1 ) { - // In order to broadcast dimensions, we set the stride for that dimension to zero... - strides[ i ] = 0; - } else { - // At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when "tiling" an array; e.g., `dim=4` and `d=2`)... - throw new Error( format( '0i55G', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); - } - } - return ndarray( getDType( arr ), getData( arr ), copy( shape ), strides, getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len -} - - -// EXPORTS // - -module.exports = broadcastArray; diff --git a/package.json b/package.json index fdd2d13..5c882e8 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Broadcast an ndarray to a specified 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,46 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-copy-indexed": "^0.2.2", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/ndarray-base-data-buffer": "^0.2.2", - "@stdlib/ndarray-base-dtype": "^0.2.2", - "@stdlib/ndarray-base-offset": "^0.2.2", - "@stdlib/ndarray-base-order": "^0.2.2", - "@stdlib/ndarray-base-shape": "^0.2.2", - "@stdlib/ndarray-base-strides": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/ndarray-array": "^0.2.1", - "@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", @@ -92,7 +29,6 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..315fe2e --- /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 97decdb..0000000 --- a/test/test.js +++ /dev/null @@ -1,511 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 broadcastArray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastArray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a desired shape which has fewer dimensions than 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() { - broadcastArray( 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() { - broadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape and an input array shape 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() { - broadcastArray( x, value ); - }; - } -}); - -tape( 'the function returns a "base" ndarray instance', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = broadcastArray( 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 = broadcastArray( 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.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, 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 = broadcastArray( x, expected ); - - actual = y.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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 a8485b1c93bbb8947a88c5380aca290f1957232e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Dec 2024 08:35:08 +0000 Subject: [PATCH 80/91] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index b4882c3..8496a36 100644 --- a/lib/main.js +++ b/lib/main.js @@ -28,7 +28,7 @@ var getOffset = require( '@stdlib/ndarray-base-offset' ); var getOrder = require( '@stdlib/ndarray-base-order' ); var getDType = require( '@stdlib/ndarray-base-dtype' ); var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -104,7 +104,7 @@ function broadcastArray( arr, shape ) { sh = getShape( arr, false ); M = sh.length; if ( N < M ) { - throw new Error( 'invalid argument. Cannot broadcast an array to a shape having fewer dimensions. Arrays can only be broadcasted to shapes having the same or more dimensions.' ); + throw new Error( format('0i50Z') ); } // Initialize a strides array... strides = []; @@ -122,7 +122,7 @@ function broadcastArray( arr, shape ) { d = sh[ j ]; dim = shape[ i ]; if ( dim !== 0 && dim < d ) { - throw new Error( format( 'invalid argument. Input array cannot be broadcast to the specified shape, as the specified shape has a dimension whose size is less than the size of the corresponding dimension in the input array. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); + throw new Error( format( '0i55F', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); } if ( d === dim ) { strides[ i ] = st[ j ]; @@ -131,7 +131,7 @@ function broadcastArray( arr, shape ) { strides[ i ] = 0; } else { // At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when "tiling" an array; e.g., `dim=4` and `d=2`)... - throw new Error( format( 'invalid argument. Input array and the specified shape are broadcast incompatible. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); + throw new Error( format( '0i55G', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); } } return ndarray( getDType( arr ), getData( arr ), copy( shape ), strides, getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len diff --git a/package.json b/package.json index 85dd6c0..26b0d41 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "@stdlib/ndarray-base-order": "^0.2.2", "@stdlib/ndarray-base-shape": "^0.2.2", "@stdlib/ndarray-base-strides": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.3", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, From e43e96cf00c5f4a0354f24a699de43c287e3820f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Dec 2024 12:42:31 +0000 Subject: [PATCH 81/91] Remove files --- index.d.ts | 80 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4927 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 89664bc..0000000 --- a/index.d.ts +++ /dev/null @@ -1,80 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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. -* -* ## Notes -* -* - The function throws an error if a provided ndarray is incompatible with a provided shape. -* - The 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. -* - The returned array is a "base" ndarray, and, thus, the returned array 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 always returns a new ndarray instance even if the input ndarray shape and the desired shape are the same. -* -* @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 -* @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 = broadcastArray( 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 broadcastArray( arr: ndarray, shape: ArrayLike ): ndarray; - - -// EXPORTS // - -export = broadcastArray; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index da0232c..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 s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy-indexed@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function j(j,a){var h,p,f,l,v,b,c,g,x;if((v=a.length)<(b=(f=e(j,!1)).length))throw new Error(m("0i50Z"));for(h=[],g=0;g=0;g--)if(!((x=b-v+g)<0)){if(c=f[x],0!==(p=a[g])&&p\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction broadcastArray( arr, shape ) {\n\tvar strides;\n\tvar dim;\n\tvar sh;\n\tvar st;\n\tvar N;\n\tvar M;\n\tvar d;\n\tvar i;\n\tvar j;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\tM = sh.length;\n\tif ( N < M ) {\n\t\tthrow new Error( format('0i50Z') );\n\t}\n\t// Initialize a strides array...\n\tstrides = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tstrides.push( 0 );\n\t}\n\t// Determine the output array strides...\n\tst = getStrides( arr, false );\n\tfor ( i = N-1; i >= 0; i-- ) {\n\t\tj = M - N + i;\n\t\tif ( j < 0 ) {\n\t\t\t// Prepended singleton dimension; stride is zero...\n\t\t\tcontinue;\n\t\t}\n\t\td = sh[ j ];\n\t\tdim = shape[ i ];\n\t\tif ( dim !== 0 && dim < d ) {\n\t\t\tthrow new Error( format( '0i55F', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t\tif ( d === dim ) {\n\t\t\tstrides[ i ] = st[ j ];\n\t\t} else if ( d === 1 ) {\n\t\t\t// In order to broadcast dimensions, we set the stride for that dimension to zero...\n\t\t\tstrides[ i ] = 0;\n\t\t} else {\n\t\t\t// At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when \"tiling\" an array; e.g., `dim=4` and `d=2`)...\n\t\t\tthrow new Error( format( '0i55G', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t}\n\treturn ndarray( getDType( arr ), getData( arr ), copy( shape ), strides, getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nexport default broadcastArray;\n"],"names":["broadcastArray","arr","shape","strides","dim","sh","st","N","M","d","i","j","length","getShape","Error","format","push","getStrides","copy","join","ndarray","getDType","getData","getOffset","getOrder"],"mappings":";;s1BA2FA,SAASA,EAAgBC,EAAKC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAJ,EAAIL,EAAMU,SAEVJ,GADAH,EAAKQ,EAAUZ,GAAK,IACbW,QAEN,MAAM,IAAIE,MAAOC,EAAO,UAIzB,IADAZ,EAAU,GACJO,EAAI,EAAGA,EAAIH,EAAGG,IACnBP,EAAQa,KAAM,GAIf,IADAV,EAAKW,EAAYhB,GAAK,GAChBS,EAAIH,EAAE,EAAGG,GAAK,EAAGA,IAEtB,MADAC,EAAIH,EAAID,EAAIG,GACH,GAAT,CAMA,GAFAD,EAAIJ,EAAIM,GAEK,KADbP,EAAMF,EAAOQ,KACKN,EAAMK,EACvB,MAAM,IAAIK,MAAOC,EAAQ,QAASG,EAAMb,GAAKc,KAAM,MAAQD,EAAMhB,GAAQiB,KAAM,MAAQT,IAExF,GAAKD,IAAML,EACVD,EAASO,GAAMJ,EAAIK,OACb,IAAW,IAANF,EAKX,MAAM,IAAIK,MAAOC,EAAQ,QAASG,EAAMb,GAAKc,KAAM,MAAQD,EAAMhB,GAAQiB,KAAM,MAAQT,IAHvFP,EAASO,GAAM,CAIf,CAdA,CAgBF,OAAOU,EAASC,EAAUpB,GAAOqB,EAASrB,GAAOiB,EAAMhB,GAASC,EAASoB,EAAWtB,GAAOuB,EAAUvB,GACtG"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 315fe2e..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 4ecd6062a465056dcd15b7ed63b80b004f3bb162 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Dec 2024 12:42:48 +0000 Subject: [PATCH 82/91] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 213 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 49 +- SECURITY.md | 5 - benchmark/benchmark.js | 161 - benchmark/benchmark.ndims.js | 110 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 65 - docs/types/test.ts | 94 - examples/index.js | 49 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 68 - lib/main.js | 143 - package.json | 68 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 511 -- 45 files changed, 4870 insertions(+), 4914 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 (96%) 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 9061165..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-12-01T06:37:08.035Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 6c59584..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-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 7ab66d5..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-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 e1434bb..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: '28 4 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -177,7 +168,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]. @@ -240,11 +231,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-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 d0243ca..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,161 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 broadcastArray = 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 = broadcastArray( 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', 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 = broadcastArray( 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', 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 = broadcastArray( 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(); -}); diff --git a/benchmark/benchmark.ndims.js b/benchmark/benchmark.ndims.js deleted file mode 100644 index 9530251..0000000 --- a/benchmark/benchmark.ndims.js +++ /dev/null @@ -1,110 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 broadcastArray = 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 = broadcastArray( 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 f51adca..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-array" -%% click B href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-array -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-array/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-array/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-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 a9d3107..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import broadcastArray from '../docs/types/index'; -export = broadcastArray; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 4f8387b..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var m=function(a,r){return function(){return r||a((r={exports:{}}).exports,r),r.exports}};var c=m(function(x,f){"use strict";var t=require("@stdlib/array-base-copy-indexed"),g=require("@stdlib/ndarray-base-ctor"),l=require("@stdlib/ndarray-base-shape"),y=require("@stdlib/ndarray-base-strides"),q=require("@stdlib/ndarray-base-offset"),b=require("@stdlib/ndarray-base-order"),w=require("@stdlib/ndarray-base-dtype"),D=require("@stdlib/ndarray-base-data-buffer"),p=require("@stdlib/string-format");function j(a,r){var i,o,s,v,n,u,d,e,h;if(n=r.length,s=l(a,!1),u=s.length,n=0;e--)if(h=u-n+e,!(h<0)){if(d=s[h],o=r[e],o!==0&&o\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction broadcastArray( arr, shape ) {\n\tvar strides;\n\tvar dim;\n\tvar sh;\n\tvar st;\n\tvar N;\n\tvar M;\n\tvar d;\n\tvar i;\n\tvar j;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\tM = sh.length;\n\tif ( N < M ) {\n\t\tthrow new Error( 'invalid argument. Cannot broadcast an array to a shape having fewer dimensions. Arrays can only be broadcasted to shapes having the same or more dimensions.' );\n\t}\n\t// Initialize a strides array...\n\tstrides = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tstrides.push( 0 );\n\t}\n\t// Determine the output array strides...\n\tst = getStrides( arr, false );\n\tfor ( i = N-1; i >= 0; i-- ) {\n\t\tj = M - N + i;\n\t\tif ( j < 0 ) {\n\t\t\t// Prepended singleton dimension; stride is zero...\n\t\t\tcontinue;\n\t\t}\n\t\td = sh[ j ];\n\t\tdim = shape[ i ];\n\t\tif ( dim !== 0 && dim < d ) {\n\t\t\tthrow new Error( format( 'invalid argument. Input array cannot be broadcast to the specified shape, as the specified shape has a dimension whose size is less than the size of the corresponding dimension in the input array. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t\tif ( d === dim ) {\n\t\t\tstrides[ i ] = st[ j ];\n\t\t} else if ( d === 1 ) {\n\t\t\t// In order to broadcast dimensions, we set the stride for that dimension to zero...\n\t\t\tstrides[ i ] = 0;\n\t\t} else {\n\t\t\t// At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when \"tiling\" an array; e.g., `dim=4` and `d=2`)...\n\t\t\tthrow new Error( format( 'invalid argument. Input array and the specified shape are broadcast incompatible. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t}\n\treturn ndarray( getDType( arr ), getData( arr ), copy( shape ), strides, getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nmodule.exports = broadcastArray;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast an ndarray to a specified shape.\n*\n* @module @stdlib/ndarray-base-broadcast-array\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var broadcastArray = require( '@stdlib/ndarray-base-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 = broadcastArray( 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,EAAO,QAAS,iCAAkC,EAClDC,EAAU,QAAS,2BAA4B,EAC/CC,EAAW,QAAS,4BAA6B,EACjDC,EAAa,QAAS,8BAA+B,EACrDC,EAAY,QAAS,6BAA8B,EACnDC,EAAW,QAAS,4BAA6B,EACjDC,EAAW,QAAS,4BAA6B,EACjDC,EAAU,QAAS,kCAAmC,EACtDC,EAAS,QAAS,uBAAwB,EA6D9C,SAASC,EAAgBC,EAAKC,EAAQ,CACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACA,EACAC,EACAC,EAKJ,GAHAH,EAAIL,EAAM,OACVG,EAAKZ,EAAUQ,EAAK,EAAM,EAC1BO,EAAIH,EAAG,OACFE,EAAIC,EACR,MAAM,IAAI,MAAO,8JAA+J,EAIjL,IADAL,EAAU,CAAC,EACLM,EAAI,EAAGA,EAAIF,EAAGE,IACnBN,EAAQ,KAAM,CAAE,EAIjB,IADAG,EAAKZ,EAAYO,EAAK,EAAM,EACtBQ,EAAIF,EAAE,EAAGE,GAAK,EAAGA,IAEtB,GADAC,EAAIF,EAAID,EAAIE,EACP,EAAAC,EAAI,GAMT,IAFA,EAAIL,EAAIK,CAAE,EACVN,EAAMF,EAAOO,CAAE,EACVL,IAAQ,GAAKA,EAAM,EACvB,MAAM,IAAI,MAAOL,EAAQ,8PAA+PR,EAAMc,CAAG,EAAE,KAAM,IAAK,EAAGd,EAAMW,CAAM,EAAE,KAAM,IAAK,EAAGO,CAAE,CAAE,EAElV,GAAK,IAAML,EACVD,EAASM,CAAE,EAAIH,EAAII,CAAE,UACV,IAAM,EAEjBP,EAASM,CAAE,EAAI,MAGf,OAAM,IAAI,MAAOV,EAAQ,2IAA4IR,EAAMc,CAAG,EAAE,KAAM,IAAK,EAAGd,EAAMW,CAAM,EAAE,KAAM,IAAK,EAAGO,CAAE,CAAE,EAGhO,OAAOjB,EAASK,EAAUI,CAAI,EAAGH,EAASG,CAAI,EAAGV,EAAMW,CAAM,EAAGC,EAASR,EAAWM,CAAI,EAAGL,EAAUK,CAAI,CAAE,CAC5G,CAKAX,EAAO,QAAUU,IChFjB,IAAIW,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "copy", "ndarray", "getShape", "getStrides", "getOffset", "getOrder", "getDType", "getData", "format", "broadcastArray", "arr", "shape", "strides", "dim", "sh", "st", "N", "M", "i", "j", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index db0f44c..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,65 +0,0 @@ - -{{alias}}( arr, shape ) - Broadcasts an ndarray to a specified shape. - - The 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. - - The returned array is a "base" ndarray, and, thus, the returned array 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. - - The function always returns a new ndarray instance even if the input ndarray - shape and the desired shape are the same. - - 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 13dcd66..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,94 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 broadcastArray = 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(); - - broadcastArray( x, [ 2, 2, 2 ] ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is not provided a first argument which is an ndarray... -{ - broadcastArray( '5', [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( 5, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( true, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( false, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( null, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( {}, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( [ '5' ], [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( ( 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(); - - broadcastArray( x, '5' ); // $ExpectError - broadcastArray( x, 5 ); // $ExpectError - broadcastArray( x, true ); // $ExpectError - broadcastArray( x, false ); // $ExpectError - broadcastArray( x, null ); // $ExpectError - broadcastArray( x, {} ); // $ExpectError - broadcastArray( x, [ '5' ] ); // $ExpectError - broadcastArray( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - - broadcastArray(); // $ExpectError - broadcastArray( x ); // $ExpectError - broadcastArray( x, [ 1, 2, 3 ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index f0dc7b6..0000000 --- a/examples/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 broadcastArray = require( './../lib' ); - -// Create a 2x2 array: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -// returns - -// Broadcast the array to 3x2x2: -var y = broadcastArray( 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 sub; -var v; -var i; -for ( i = 0; i < N; i++ ) { - v = y.iget( i ); - sub = ind2sub( sh, i ); - console.log( 'Y[%s] = %d', sub.join( ', ' ), v ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index 672e358..89664bc 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..da0232c --- /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 s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy-indexed@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function j(j,a){var h,p,f,l,v,b,c,g,x;if((v=a.length)<(b=(f=e(j,!1)).length))throw new Error(m("0i50Z"));for(h=[],g=0;g=0;g--)if(!((x=b-v+g)<0)){if(c=f[x],0!==(p=a[g])&&p\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction broadcastArray( arr, shape ) {\n\tvar strides;\n\tvar dim;\n\tvar sh;\n\tvar st;\n\tvar N;\n\tvar M;\n\tvar d;\n\tvar i;\n\tvar j;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\tM = sh.length;\n\tif ( N < M ) {\n\t\tthrow new Error( format('0i50Z') );\n\t}\n\t// Initialize a strides array...\n\tstrides = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tstrides.push( 0 );\n\t}\n\t// Determine the output array strides...\n\tst = getStrides( arr, false );\n\tfor ( i = N-1; i >= 0; i-- ) {\n\t\tj = M - N + i;\n\t\tif ( j < 0 ) {\n\t\t\t// Prepended singleton dimension; stride is zero...\n\t\t\tcontinue;\n\t\t}\n\t\td = sh[ j ];\n\t\tdim = shape[ i ];\n\t\tif ( dim !== 0 && dim < d ) {\n\t\t\tthrow new Error( format( '0i55F', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t\tif ( d === dim ) {\n\t\t\tstrides[ i ] = st[ j ];\n\t\t} else if ( d === 1 ) {\n\t\t\t// In order to broadcast dimensions, we set the stride for that dimension to zero...\n\t\t\tstrides[ i ] = 0;\n\t\t} else {\n\t\t\t// At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when \"tiling\" an array; e.g., `dim=4` and `d=2`)...\n\t\t\tthrow new Error( format( '0i55G', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t}\n\treturn ndarray( getDType( arr ), getData( arr ), copy( shape ), strides, getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nexport default broadcastArray;\n"],"names":["broadcastArray","arr","shape","strides","dim","sh","st","N","M","d","i","j","length","getShape","Error","format","push","getStrides","copy","join","ndarray","getDType","getData","getOffset","getOrder"],"mappings":";;s1BA2FA,SAASA,EAAgBC,EAAKC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAJ,EAAIL,EAAMU,SAEVJ,GADAH,EAAKQ,EAAUZ,GAAK,IACbW,QAEN,MAAM,IAAIE,MAAOC,EAAO,UAIzB,IADAZ,EAAU,GACJO,EAAI,EAAGA,EAAIH,EAAGG,IACnBP,EAAQa,KAAM,GAIf,IADAV,EAAKW,EAAYhB,GAAK,GAChBS,EAAIH,EAAE,EAAGG,GAAK,EAAGA,IAEtB,MADAC,EAAIH,EAAID,EAAIG,GACH,GAAT,CAMA,GAFAD,EAAIJ,EAAIM,GAEK,KADbP,EAAMF,EAAOQ,KACKN,EAAMK,EACvB,MAAM,IAAIK,MAAOC,EAAQ,QAASG,EAAMb,GAAKc,KAAM,MAAQD,EAAMhB,GAAQiB,KAAM,MAAQT,IAExF,GAAKD,IAAML,EACVD,EAASO,GAAMJ,EAAIK,OACb,IAAW,IAANF,EAKX,MAAM,IAAIK,MAAOC,EAAQ,QAASG,EAAMb,GAAKc,KAAM,MAAQD,EAAMhB,GAAQiB,KAAM,MAAQT,IAHvFP,EAASO,GAAM,CAIf,CAdA,CAgBF,OAAOU,EAASC,EAAUpB,GAAOqB,EAASrB,GAAOiB,EAAMhB,GAASC,EAASoB,EAAWtB,GAAOuB,EAAUvB,GACtG"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index b6aaa86..0000000 --- a/lib/index.js +++ /dev/null @@ -1,68 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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. -* -* @module @stdlib/ndarray-base-broadcast-array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var broadcastArray = require( '@stdlib/ndarray-base-broadcast-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = broadcastArray( 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 8496a36..0000000 --- a/lib/main.js +++ /dev/null @@ -1,143 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var copy = require( '@stdlib/array-base-copy-indexed' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require( '@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Broadcasts an ndarray to a specified shape. -* -* ## Notes -* -* - The 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. -* -* @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 = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] ); -* // throws -*/ -function broadcastArray( arr, shape ) { - var strides; - var dim; - var sh; - var st; - var N; - var M; - var d; - var i; - var j; - - N = shape.length; - sh = getShape( arr, false ); - M = sh.length; - if ( N < M ) { - throw new Error( format('0i50Z') ); - } - // Initialize a strides array... - strides = []; - for ( i = 0; i < N; i++ ) { - strides.push( 0 ); - } - // Determine the output array strides... - st = getStrides( arr, false ); - for ( i = N-1; i >= 0; i-- ) { - j = M - N + i; - if ( j < 0 ) { - // Prepended singleton dimension; stride is zero... - continue; - } - d = sh[ j ]; - dim = shape[ i ]; - if ( dim !== 0 && dim < d ) { - throw new Error( format( '0i55F', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); - } - if ( d === dim ) { - strides[ i ] = st[ j ]; - } else if ( d === 1 ) { - // In order to broadcast dimensions, we set the stride for that dimension to zero... - strides[ i ] = 0; - } else { - // At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when "tiling" an array; e.g., `dim=4` and `d=2`)... - throw new Error( format( '0i55G', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); - } - } - return ndarray( getDType( arr ), getData( arr ), copy( shape ), strides, getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len -} - - -// EXPORTS // - -module.exports = broadcastArray; diff --git a/package.json b/package.json index 26b0d41..5c882e8 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Broadcast an ndarray to a specified 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,46 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-copy-indexed": "^0.2.2", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/ndarray-base-data-buffer": "^0.2.2", - "@stdlib/ndarray-base-dtype": "^0.2.2", - "@stdlib/ndarray-base-offset": "^0.2.2", - "@stdlib/ndarray-base-order": "^0.2.2", - "@stdlib/ndarray-base-shape": "^0.2.2", - "@stdlib/ndarray-base-strides": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/ndarray-array": "^0.2.1", - "@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", @@ -92,7 +29,6 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..315fe2e --- /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 97decdb..0000000 --- a/test/test.js +++ /dev/null @@ -1,511 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 broadcastArray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastArray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a desired shape which has fewer dimensions than 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() { - broadcastArray( 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() { - broadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape and an input array shape 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() { - broadcastArray( x, value ); - }; - } -}); - -tape( 'the function returns a "base" ndarray instance', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = broadcastArray( 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 = broadcastArray( 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.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, 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 = broadcastArray( x, expected ); - - actual = y.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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 178fd09eb15099efa57693ca86ae6d52ed19d4c8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 3 Feb 2025 01:26:38 +0000 Subject: [PATCH 83/91] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index b4882c3..8496a36 100644 --- a/lib/main.js +++ b/lib/main.js @@ -28,7 +28,7 @@ var getOffset = require( '@stdlib/ndarray-base-offset' ); var getOrder = require( '@stdlib/ndarray-base-order' ); var getDType = require( '@stdlib/ndarray-base-dtype' ); var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -104,7 +104,7 @@ function broadcastArray( arr, shape ) { sh = getShape( arr, false ); M = sh.length; if ( N < M ) { - throw new Error( 'invalid argument. Cannot broadcast an array to a shape having fewer dimensions. Arrays can only be broadcasted to shapes having the same or more dimensions.' ); + throw new Error( format('0i50Z') ); } // Initialize a strides array... strides = []; @@ -122,7 +122,7 @@ function broadcastArray( arr, shape ) { d = sh[ j ]; dim = shape[ i ]; if ( dim !== 0 && dim < d ) { - throw new Error( format( 'invalid argument. Input array cannot be broadcast to the specified shape, as the specified shape has a dimension whose size is less than the size of the corresponding dimension in the input array. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); + throw new Error( format( '0i55F', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); } if ( d === dim ) { strides[ i ] = st[ j ]; @@ -131,7 +131,7 @@ function broadcastArray( arr, shape ) { strides[ i ] = 0; } else { // At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when "tiling" an array; e.g., `dim=4` and `d=2`)... - throw new Error( format( 'invalid argument. Input array and the specified shape are broadcast incompatible. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); + throw new Error( format( '0i55G', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); } } return ndarray( getDType( arr ), getData( arr ), copy( shape ), strides, getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len diff --git a/package.json b/package.json index 85dd6c0..26b0d41 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "@stdlib/ndarray-base-order": "^0.2.2", "@stdlib/ndarray-base-shape": "^0.2.2", "@stdlib/ndarray-base-strides": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.3", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, From 07141131aef9081acc718bb570e44565bed668af Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 3 Feb 2025 01:57:07 +0000 Subject: [PATCH 84/91] Remove files --- index.d.ts | 80 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4927 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 89664bc..0000000 --- a/index.d.ts +++ /dev/null @@ -1,80 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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. -* -* ## Notes -* -* - The function throws an error if a provided ndarray is incompatible with a provided shape. -* - The 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. -* - The returned array is a "base" ndarray, and, thus, the returned array 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 always returns a new ndarray instance even if the input ndarray shape and the desired shape are the same. -* -* @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 -* @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 = broadcastArray( 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 broadcastArray( arr: ndarray, shape: ArrayLike ): ndarray; - - -// EXPORTS // - -export = broadcastArray; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index da0232c..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 s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy-indexed@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function j(j,a){var h,p,f,l,v,b,c,g,x;if((v=a.length)<(b=(f=e(j,!1)).length))throw new Error(m("0i50Z"));for(h=[],g=0;g=0;g--)if(!((x=b-v+g)<0)){if(c=f[x],0!==(p=a[g])&&p\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction broadcastArray( arr, shape ) {\n\tvar strides;\n\tvar dim;\n\tvar sh;\n\tvar st;\n\tvar N;\n\tvar M;\n\tvar d;\n\tvar i;\n\tvar j;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\tM = sh.length;\n\tif ( N < M ) {\n\t\tthrow new Error( format('0i50Z') );\n\t}\n\t// Initialize a strides array...\n\tstrides = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tstrides.push( 0 );\n\t}\n\t// Determine the output array strides...\n\tst = getStrides( arr, false );\n\tfor ( i = N-1; i >= 0; i-- ) {\n\t\tj = M - N + i;\n\t\tif ( j < 0 ) {\n\t\t\t// Prepended singleton dimension; stride is zero...\n\t\t\tcontinue;\n\t\t}\n\t\td = sh[ j ];\n\t\tdim = shape[ i ];\n\t\tif ( dim !== 0 && dim < d ) {\n\t\t\tthrow new Error( format( '0i55F', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t\tif ( d === dim ) {\n\t\t\tstrides[ i ] = st[ j ];\n\t\t} else if ( d === 1 ) {\n\t\t\t// In order to broadcast dimensions, we set the stride for that dimension to zero...\n\t\t\tstrides[ i ] = 0;\n\t\t} else {\n\t\t\t// At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when \"tiling\" an array; e.g., `dim=4` and `d=2`)...\n\t\t\tthrow new Error( format( '0i55G', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t}\n\treturn ndarray( getDType( arr ), getData( arr ), copy( shape ), strides, getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nexport default broadcastArray;\n"],"names":["broadcastArray","arr","shape","strides","dim","sh","st","N","M","d","i","j","length","getShape","Error","format","push","getStrides","copy","join","ndarray","getDType","getData","getOffset","getOrder"],"mappings":";;s1BA2FA,SAASA,EAAgBC,EAAKC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAJ,EAAIL,EAAMU,SAEVJ,GADAH,EAAKQ,EAAUZ,GAAK,IACbW,QAEN,MAAM,IAAIE,MAAOC,EAAO,UAIzB,IADAZ,EAAU,GACJO,EAAI,EAAGA,EAAIH,EAAGG,IACnBP,EAAQa,KAAM,GAIf,IADAV,EAAKW,EAAYhB,GAAK,GAChBS,EAAIH,EAAE,EAAGG,GAAK,EAAGA,IAEtB,MADAC,EAAIH,EAAID,EAAIG,GACH,GAAT,CAMA,GAFAD,EAAIJ,EAAIM,GAEK,KADbP,EAAMF,EAAOQ,KACKN,EAAMK,EACvB,MAAM,IAAIK,MAAOC,EAAQ,QAASG,EAAMb,GAAKc,KAAM,MAAQD,EAAMhB,GAAQiB,KAAM,MAAQT,IAExF,GAAKD,IAAML,EACVD,EAASO,GAAMJ,EAAIK,OACb,IAAW,IAANF,EAKX,MAAM,IAAIK,MAAOC,EAAQ,QAASG,EAAMb,GAAKc,KAAM,MAAQD,EAAMhB,GAAQiB,KAAM,MAAQT,IAHvFP,EAASO,GAAM,CAIf,CAdA,CAgBF,OAAOU,EAASC,EAAUpB,GAAOqB,EAASrB,GAAOiB,EAAMhB,GAASC,EAASoB,EAAWtB,GAAOuB,EAAUvB,GACtG"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 315fe2e..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From f9986dd317b9441f672acf8824ba8dc623a545e3 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 3 Feb 2025 01:57:34 +0000 Subject: [PATCH 85/91] Auto-generated commit --- .editorconfig | 180 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 213 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 49 +- SECURITY.md | 5 - benchmark/benchmark.js | 161 - benchmark/benchmark.ndims.js | 110 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 65 - docs/types/test.ts | 94 - examples/index.js | 49 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 68 - lib/main.js | 143 - package.json | 68 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 511 -- 45 files changed, 4870 insertions(+), 4913 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 (96%) 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 95d0705..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2025-02-03T01:12:41.168Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 6c59584..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-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 7ab66d5..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-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 e1434bb..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: '28 4 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -177,7 +168,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]. @@ -240,11 +231,11 @@ Copyright © 2016-2025. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-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 d0243ca..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,161 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 broadcastArray = 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 = broadcastArray( 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', 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 = broadcastArray( 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', 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 = broadcastArray( 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(); -}); diff --git a/benchmark/benchmark.ndims.js b/benchmark/benchmark.ndims.js deleted file mode 100644 index 9530251..0000000 --- a/benchmark/benchmark.ndims.js +++ /dev/null @@ -1,110 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 broadcastArray = 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 = broadcastArray( 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 f51adca..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-array" -%% click B href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-array -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-array/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-array/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-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 a9d3107..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import broadcastArray from '../docs/types/index'; -export = broadcastArray; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 4f8387b..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var m=function(a,r){return function(){return r||a((r={exports:{}}).exports,r),r.exports}};var c=m(function(x,f){"use strict";var t=require("@stdlib/array-base-copy-indexed"),g=require("@stdlib/ndarray-base-ctor"),l=require("@stdlib/ndarray-base-shape"),y=require("@stdlib/ndarray-base-strides"),q=require("@stdlib/ndarray-base-offset"),b=require("@stdlib/ndarray-base-order"),w=require("@stdlib/ndarray-base-dtype"),D=require("@stdlib/ndarray-base-data-buffer"),p=require("@stdlib/string-format");function j(a,r){var i,o,s,v,n,u,d,e,h;if(n=r.length,s=l(a,!1),u=s.length,n=0;e--)if(h=u-n+e,!(h<0)){if(d=s[h],o=r[e],o!==0&&o\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction broadcastArray( arr, shape ) {\n\tvar strides;\n\tvar dim;\n\tvar sh;\n\tvar st;\n\tvar N;\n\tvar M;\n\tvar d;\n\tvar i;\n\tvar j;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\tM = sh.length;\n\tif ( N < M ) {\n\t\tthrow new Error( 'invalid argument. Cannot broadcast an array to a shape having fewer dimensions. Arrays can only be broadcasted to shapes having the same or more dimensions.' );\n\t}\n\t// Initialize a strides array...\n\tstrides = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tstrides.push( 0 );\n\t}\n\t// Determine the output array strides...\n\tst = getStrides( arr, false );\n\tfor ( i = N-1; i >= 0; i-- ) {\n\t\tj = M - N + i;\n\t\tif ( j < 0 ) {\n\t\t\t// Prepended singleton dimension; stride is zero...\n\t\t\tcontinue;\n\t\t}\n\t\td = sh[ j ];\n\t\tdim = shape[ i ];\n\t\tif ( dim !== 0 && dim < d ) {\n\t\t\tthrow new Error( format( 'invalid argument. Input array cannot be broadcast to the specified shape, as the specified shape has a dimension whose size is less than the size of the corresponding dimension in the input array. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t\tif ( d === dim ) {\n\t\t\tstrides[ i ] = st[ j ];\n\t\t} else if ( d === 1 ) {\n\t\t\t// In order to broadcast dimensions, we set the stride for that dimension to zero...\n\t\t\tstrides[ i ] = 0;\n\t\t} else {\n\t\t\t// At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when \"tiling\" an array; e.g., `dim=4` and `d=2`)...\n\t\t\tthrow new Error( format( 'invalid argument. Input array and the specified shape are broadcast incompatible. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t}\n\treturn ndarray( getDType( arr ), getData( arr ), copy( shape ), strides, getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nmodule.exports = broadcastArray;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast an ndarray to a specified shape.\n*\n* @module @stdlib/ndarray-base-broadcast-array\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var broadcastArray = require( '@stdlib/ndarray-base-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 = broadcastArray( 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,EAAO,QAAS,iCAAkC,EAClDC,EAAU,QAAS,2BAA4B,EAC/CC,EAAW,QAAS,4BAA6B,EACjDC,EAAa,QAAS,8BAA+B,EACrDC,EAAY,QAAS,6BAA8B,EACnDC,EAAW,QAAS,4BAA6B,EACjDC,EAAW,QAAS,4BAA6B,EACjDC,EAAU,QAAS,kCAAmC,EACtDC,EAAS,QAAS,uBAAwB,EA6D9C,SAASC,EAAgBC,EAAKC,EAAQ,CACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACA,EACAC,EACAC,EAKJ,GAHAH,EAAIL,EAAM,OACVG,EAAKZ,EAAUQ,EAAK,EAAM,EAC1BO,EAAIH,EAAG,OACFE,EAAIC,EACR,MAAM,IAAI,MAAO,8JAA+J,EAIjL,IADAL,EAAU,CAAC,EACLM,EAAI,EAAGA,EAAIF,EAAGE,IACnBN,EAAQ,KAAM,CAAE,EAIjB,IADAG,EAAKZ,EAAYO,EAAK,EAAM,EACtBQ,EAAIF,EAAE,EAAGE,GAAK,EAAGA,IAEtB,GADAC,EAAIF,EAAID,EAAIE,EACP,EAAAC,EAAI,GAMT,IAFA,EAAIL,EAAIK,CAAE,EACVN,EAAMF,EAAOO,CAAE,EACVL,IAAQ,GAAKA,EAAM,EACvB,MAAM,IAAI,MAAOL,EAAQ,8PAA+PR,EAAMc,CAAG,EAAE,KAAM,IAAK,EAAGd,EAAMW,CAAM,EAAE,KAAM,IAAK,EAAGO,CAAE,CAAE,EAElV,GAAK,IAAML,EACVD,EAASM,CAAE,EAAIH,EAAII,CAAE,UACV,IAAM,EAEjBP,EAASM,CAAE,EAAI,MAGf,OAAM,IAAI,MAAOV,EAAQ,2IAA4IR,EAAMc,CAAG,EAAE,KAAM,IAAK,EAAGd,EAAMW,CAAM,EAAE,KAAM,IAAK,EAAGO,CAAE,CAAE,EAGhO,OAAOjB,EAASK,EAAUI,CAAI,EAAGH,EAASG,CAAI,EAAGV,EAAMW,CAAM,EAAGC,EAASR,EAAWM,CAAI,EAAGL,EAAUK,CAAI,CAAE,CAC5G,CAKAX,EAAO,QAAUU,IChFjB,IAAIW,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "copy", "ndarray", "getShape", "getStrides", "getOffset", "getOrder", "getDType", "getData", "format", "broadcastArray", "arr", "shape", "strides", "dim", "sh", "st", "N", "M", "i", "j", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index db0f44c..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,65 +0,0 @@ - -{{alias}}( arr, shape ) - Broadcasts an ndarray to a specified shape. - - The 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. - - The returned array is a "base" ndarray, and, thus, the returned array 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. - - The function always returns a new ndarray instance even if the input ndarray - shape and the desired shape are the same. - - 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 13dcd66..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,94 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 broadcastArray = 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(); - - broadcastArray( x, [ 2, 2, 2 ] ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is not provided a first argument which is an ndarray... -{ - broadcastArray( '5', [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( 5, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( true, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( false, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( null, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( {}, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( [ '5' ], [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( ( 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(); - - broadcastArray( x, '5' ); // $ExpectError - broadcastArray( x, 5 ); // $ExpectError - broadcastArray( x, true ); // $ExpectError - broadcastArray( x, false ); // $ExpectError - broadcastArray( x, null ); // $ExpectError - broadcastArray( x, {} ); // $ExpectError - broadcastArray( x, [ '5' ] ); // $ExpectError - broadcastArray( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - - broadcastArray(); // $ExpectError - broadcastArray( x ); // $ExpectError - broadcastArray( x, [ 1, 2, 3 ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index f0dc7b6..0000000 --- a/examples/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 broadcastArray = require( './../lib' ); - -// Create a 2x2 array: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -// returns - -// Broadcast the array to 3x2x2: -var y = broadcastArray( 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 sub; -var v; -var i; -for ( i = 0; i < N; i++ ) { - v = y.iget( i ); - sub = ind2sub( sh, i ); - console.log( 'Y[%s] = %d', sub.join( ', ' ), v ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index 672e358..89664bc 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..9a4d472 --- /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 s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy-indexed@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function j(j,a){var h,p,f,l,v,b,c,g,x;if((v=a.length)<(b=(f=e(j,!1)).length))throw new Error(m("0i50Z"));for(h=[],g=0;g=0;g--)if(!((x=b-v+g)<0)){if(c=f[x],0!==(p=a[g])&&p\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction broadcastArray( arr, shape ) {\n\tvar strides;\n\tvar dim;\n\tvar sh;\n\tvar st;\n\tvar N;\n\tvar M;\n\tvar d;\n\tvar i;\n\tvar j;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\tM = sh.length;\n\tif ( N < M ) {\n\t\tthrow new Error( format('0i50Z') );\n\t}\n\t// Initialize a strides array...\n\tstrides = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tstrides.push( 0 );\n\t}\n\t// Determine the output array strides...\n\tst = getStrides( arr, false );\n\tfor ( i = N-1; i >= 0; i-- ) {\n\t\tj = M - N + i;\n\t\tif ( j < 0 ) {\n\t\t\t// Prepended singleton dimension; stride is zero...\n\t\t\tcontinue;\n\t\t}\n\t\td = sh[ j ];\n\t\tdim = shape[ i ];\n\t\tif ( dim !== 0 && dim < d ) {\n\t\t\tthrow new Error( format( '0i55F', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t\tif ( d === dim ) {\n\t\t\tstrides[ i ] = st[ j ];\n\t\t} else if ( d === 1 ) {\n\t\t\t// In order to broadcast dimensions, we set the stride for that dimension to zero...\n\t\t\tstrides[ i ] = 0;\n\t\t} else {\n\t\t\t// At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when \"tiling\" an array; e.g., `dim=4` and `d=2`)...\n\t\t\tthrow new Error( format( '0i55G', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t}\n\treturn ndarray( getDType( arr ), getData( arr ), copy( shape ), strides, getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nexport default broadcastArray;\n"],"names":["broadcastArray","arr","shape","strides","dim","sh","st","N","M","d","i","j","length","getShape","Error","format","push","getStrides","copy","join","ndarray","getDType","getData","getOffset","getOrder"],"mappings":";;s1BA2FA,SAASA,EAAgBC,EAAKC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAJ,EAAIL,EAAMU,SAEVJ,GADAH,EAAKQ,EAAUZ,GAAK,IACbW,QAEN,MAAM,IAAIE,MAAOC,EAAO,UAIzB,IADAZ,EAAU,GACJO,EAAI,EAAGA,EAAIH,EAAGG,IACnBP,EAAQa,KAAM,GAIf,IADAV,EAAKW,EAAYhB,GAAK,GAChBS,EAAIH,EAAE,EAAGG,GAAK,EAAGA,IAEtB,MADAC,EAAIH,EAAID,EAAIG,GACH,GAAT,CAMA,GAFAD,EAAIJ,EAAIM,GAEK,KADbP,EAAMF,EAAOQ,KACKN,EAAMK,EACvB,MAAM,IAAIK,MAAOC,EAAQ,QAASG,EAAMb,GAAKc,KAAM,MAAQD,EAAMhB,GAAQiB,KAAM,MAAQT,IAExF,GAAKD,IAAML,EACVD,EAASO,GAAMJ,EAAIK,OACb,IAAW,IAANF,EAKX,MAAM,IAAIK,MAAOC,EAAQ,QAASG,EAAMb,GAAKc,KAAM,MAAQD,EAAMhB,GAAQiB,KAAM,MAAQT,IAHvFP,EAASO,GAAM,CAIf,CAdA,CAgBF,OAAOU,EAASC,EAAUpB,GAAOqB,EAASrB,GAAOiB,EAAMhB,GAASC,EAASoB,EAAWtB,GAAOuB,EAAUvB,GACtG"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index b6aaa86..0000000 --- a/lib/index.js +++ /dev/null @@ -1,68 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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. -* -* @module @stdlib/ndarray-base-broadcast-array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var broadcastArray = require( '@stdlib/ndarray-base-broadcast-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = broadcastArray( 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 8496a36..0000000 --- a/lib/main.js +++ /dev/null @@ -1,143 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var copy = require( '@stdlib/array-base-copy-indexed' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require( '@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Broadcasts an ndarray to a specified shape. -* -* ## Notes -* -* - The 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. -* -* @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 = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] ); -* // throws -*/ -function broadcastArray( arr, shape ) { - var strides; - var dim; - var sh; - var st; - var N; - var M; - var d; - var i; - var j; - - N = shape.length; - sh = getShape( arr, false ); - M = sh.length; - if ( N < M ) { - throw new Error( format('0i50Z') ); - } - // Initialize a strides array... - strides = []; - for ( i = 0; i < N; i++ ) { - strides.push( 0 ); - } - // Determine the output array strides... - st = getStrides( arr, false ); - for ( i = N-1; i >= 0; i-- ) { - j = M - N + i; - if ( j < 0 ) { - // Prepended singleton dimension; stride is zero... - continue; - } - d = sh[ j ]; - dim = shape[ i ]; - if ( dim !== 0 && dim < d ) { - throw new Error( format( '0i55F', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); - } - if ( d === dim ) { - strides[ i ] = st[ j ]; - } else if ( d === 1 ) { - // In order to broadcast dimensions, we set the stride for that dimension to zero... - strides[ i ] = 0; - } else { - // At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when "tiling" an array; e.g., `dim=4` and `d=2`)... - throw new Error( format( '0i55G', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); - } - } - return ndarray( getDType( arr ), getData( arr ), copy( shape ), strides, getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len -} - - -// EXPORTS // - -module.exports = broadcastArray; diff --git a/package.json b/package.json index 26b0d41..5c882e8 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Broadcast an ndarray to a specified 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,46 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-copy-indexed": "^0.2.2", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/ndarray-base-data-buffer": "^0.2.2", - "@stdlib/ndarray-base-dtype": "^0.2.2", - "@stdlib/ndarray-base-offset": "^0.2.2", - "@stdlib/ndarray-base-order": "^0.2.2", - "@stdlib/ndarray-base-shape": "^0.2.2", - "@stdlib/ndarray-base-strides": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/ndarray-array": "^0.2.1", - "@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", @@ -92,7 +29,6 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..315fe2e --- /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 97decdb..0000000 --- a/test/test.js +++ /dev/null @@ -1,511 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 broadcastArray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastArray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a desired shape which has fewer dimensions than 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() { - broadcastArray( 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() { - broadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape and an input array shape 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() { - broadcastArray( x, value ); - }; - } -}); - -tape( 'the function returns a "base" ndarray instance', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = broadcastArray( 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 = broadcastArray( 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.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, 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 = broadcastArray( x, expected ); - - actual = y.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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 889bf1e72f2c2ed45aaf822e077427b461b68ecd Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 7 Apr 2025 00:53:59 +0000 Subject: [PATCH 86/91] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index b4882c3..8496a36 100644 --- a/lib/main.js +++ b/lib/main.js @@ -28,7 +28,7 @@ var getOffset = require( '@stdlib/ndarray-base-offset' ); var getOrder = require( '@stdlib/ndarray-base-order' ); var getDType = require( '@stdlib/ndarray-base-dtype' ); var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -104,7 +104,7 @@ function broadcastArray( arr, shape ) { sh = getShape( arr, false ); M = sh.length; if ( N < M ) { - throw new Error( 'invalid argument. Cannot broadcast an array to a shape having fewer dimensions. Arrays can only be broadcasted to shapes having the same or more dimensions.' ); + throw new Error( format('0i50Z') ); } // Initialize a strides array... strides = []; @@ -122,7 +122,7 @@ function broadcastArray( arr, shape ) { d = sh[ j ]; dim = shape[ i ]; if ( dim !== 0 && dim < d ) { - throw new Error( format( 'invalid argument. Input array cannot be broadcast to the specified shape, as the specified shape has a dimension whose size is less than the size of the corresponding dimension in the input array. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); + throw new Error( format( '0i55F', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); } if ( d === dim ) { strides[ i ] = st[ j ]; @@ -131,7 +131,7 @@ function broadcastArray( arr, shape ) { strides[ i ] = 0; } else { // At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when "tiling" an array; e.g., `dim=4` and `d=2`)... - throw new Error( format( 'invalid argument. Input array and the specified shape are broadcast incompatible. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); + throw new Error( format( '0i55G', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); } } return ndarray( getDType( arr ), getData( arr ), copy( shape ), strides, getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len diff --git a/package.json b/package.json index 85dd6c0..26b0d41 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "@stdlib/ndarray-base-order": "^0.2.2", "@stdlib/ndarray-base-shape": "^0.2.2", "@stdlib/ndarray-base-strides": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.3", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, From 5a9364937464276139eb478da08d852565a4eda8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 7 Apr 2025 01:04:48 +0000 Subject: [PATCH 87/91] Remove files --- index.d.ts | 80 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4927 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 89664bc..0000000 --- a/index.d.ts +++ /dev/null @@ -1,80 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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. -* -* ## Notes -* -* - The function throws an error if a provided ndarray is incompatible with a provided shape. -* - The 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. -* - The returned array is a "base" ndarray, and, thus, the returned array 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 always returns a new ndarray instance even if the input ndarray shape and the desired shape are the same. -* -* @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 -* @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 = broadcastArray( 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 broadcastArray( arr: ndarray, shape: ArrayLike ): ndarray; - - -// EXPORTS // - -export = broadcastArray; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 9a4d472..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 s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy-indexed@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function j(j,a){var h,p,f,l,v,b,c,g,x;if((v=a.length)<(b=(f=e(j,!1)).length))throw new Error(m("0i50Z"));for(h=[],g=0;g=0;g--)if(!((x=b-v+g)<0)){if(c=f[x],0!==(p=a[g])&&p\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction broadcastArray( arr, shape ) {\n\tvar strides;\n\tvar dim;\n\tvar sh;\n\tvar st;\n\tvar N;\n\tvar M;\n\tvar d;\n\tvar i;\n\tvar j;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\tM = sh.length;\n\tif ( N < M ) {\n\t\tthrow new Error( format('0i50Z') );\n\t}\n\t// Initialize a strides array...\n\tstrides = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tstrides.push( 0 );\n\t}\n\t// Determine the output array strides...\n\tst = getStrides( arr, false );\n\tfor ( i = N-1; i >= 0; i-- ) {\n\t\tj = M - N + i;\n\t\tif ( j < 0 ) {\n\t\t\t// Prepended singleton dimension; stride is zero...\n\t\t\tcontinue;\n\t\t}\n\t\td = sh[ j ];\n\t\tdim = shape[ i ];\n\t\tif ( dim !== 0 && dim < d ) {\n\t\t\tthrow new Error( format( '0i55F', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t\tif ( d === dim ) {\n\t\t\tstrides[ i ] = st[ j ];\n\t\t} else if ( d === 1 ) {\n\t\t\t// In order to broadcast dimensions, we set the stride for that dimension to zero...\n\t\t\tstrides[ i ] = 0;\n\t\t} else {\n\t\t\t// At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when \"tiling\" an array; e.g., `dim=4` and `d=2`)...\n\t\t\tthrow new Error( format( '0i55G', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t}\n\treturn ndarray( getDType( arr ), getData( arr ), copy( shape ), strides, getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nexport default broadcastArray;\n"],"names":["broadcastArray","arr","shape","strides","dim","sh","st","N","M","d","i","j","length","getShape","Error","format","push","getStrides","copy","join","ndarray","getDType","getData","getOffset","getOrder"],"mappings":";;s1BA2FA,SAASA,EAAgBC,EAAKC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAJ,EAAIL,EAAMU,SAEVJ,GADAH,EAAKQ,EAAUZ,GAAK,IACbW,QAEN,MAAM,IAAIE,MAAOC,EAAO,UAIzB,IADAZ,EAAU,GACJO,EAAI,EAAGA,EAAIH,EAAGG,IACnBP,EAAQa,KAAM,GAIf,IADAV,EAAKW,EAAYhB,GAAK,GAChBS,EAAIH,EAAE,EAAGG,GAAK,EAAGA,IAEtB,MADAC,EAAIH,EAAID,EAAIG,GACH,GAAT,CAMA,GAFAD,EAAIJ,EAAIM,GAEK,KADbP,EAAMF,EAAOQ,KACKN,EAAMK,EACvB,MAAM,IAAIK,MAAOC,EAAQ,QAASG,EAAMb,GAAKc,KAAM,MAAQD,EAAMhB,GAAQiB,KAAM,MAAQT,IAExF,GAAKD,IAAML,EACVD,EAASO,GAAMJ,EAAIK,OACb,IAAW,IAANF,EAKX,MAAM,IAAIK,MAAOC,EAAQ,QAASG,EAAMb,GAAKc,KAAM,MAAQD,EAAMhB,GAAQiB,KAAM,MAAQT,IAHvFP,EAASO,GAAM,CAIf,CAdA,CAgBF,OAAOU,EAASC,EAAUpB,GAAOqB,EAASrB,GAAOiB,EAAMhB,GAASC,EAASoB,EAAWtB,GAAOuB,EAAUvB,GACtG"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 315fe2e..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 404e7c3797b4454bd8034b8db4f22ff243edf09b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 7 Apr 2025 01:05:23 +0000 Subject: [PATCH 88/91] Auto-generated commit --- .editorconfig | 180 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 194 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 213 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 49 +- SECURITY.md | 5 - benchmark/benchmark.js | 161 - benchmark/benchmark.ndims.js | 110 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 65 - docs/types/test.ts | 94 - examples/index.js | 49 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 68 - lib/main.js | 143 - package.json | 68 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 511 -- 45 files changed, 4870 insertions(+), 4917 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 (96%) 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 575c5bf..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2025-04-07T00:52:15.135Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 9b42339..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-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 7ab66d5..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-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 e1434bb..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: '28 4 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -177,7 +168,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]. @@ -240,11 +231,11 @@ Copyright © 2016-2025. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-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 d0243ca..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,161 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 broadcastArray = 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 = broadcastArray( 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', 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 = broadcastArray( 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', 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 = broadcastArray( 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(); -}); diff --git a/benchmark/benchmark.ndims.js b/benchmark/benchmark.ndims.js deleted file mode 100644 index 9530251..0000000 --- a/benchmark/benchmark.ndims.js +++ /dev/null @@ -1,110 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 broadcastArray = 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 = broadcastArray( 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 f51adca..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-array" -%% click B href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-array -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-array/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-array/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-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 a9d3107..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import broadcastArray from '../docs/types/index'; -export = broadcastArray; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 4f8387b..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var m=function(a,r){return function(){return r||a((r={exports:{}}).exports,r),r.exports}};var c=m(function(x,f){"use strict";var t=require("@stdlib/array-base-copy-indexed"),g=require("@stdlib/ndarray-base-ctor"),l=require("@stdlib/ndarray-base-shape"),y=require("@stdlib/ndarray-base-strides"),q=require("@stdlib/ndarray-base-offset"),b=require("@stdlib/ndarray-base-order"),w=require("@stdlib/ndarray-base-dtype"),D=require("@stdlib/ndarray-base-data-buffer"),p=require("@stdlib/string-format");function j(a,r){var i,o,s,v,n,u,d,e,h;if(n=r.length,s=l(a,!1),u=s.length,n=0;e--)if(h=u-n+e,!(h<0)){if(d=s[h],o=r[e],o!==0&&o\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction broadcastArray( arr, shape ) {\n\tvar strides;\n\tvar dim;\n\tvar sh;\n\tvar st;\n\tvar N;\n\tvar M;\n\tvar d;\n\tvar i;\n\tvar j;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\tM = sh.length;\n\tif ( N < M ) {\n\t\tthrow new Error( 'invalid argument. Cannot broadcast an array to a shape having fewer dimensions. Arrays can only be broadcasted to shapes having the same or more dimensions.' );\n\t}\n\t// Initialize a strides array...\n\tstrides = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tstrides.push( 0 );\n\t}\n\t// Determine the output array strides...\n\tst = getStrides( arr, false );\n\tfor ( i = N-1; i >= 0; i-- ) {\n\t\tj = M - N + i;\n\t\tif ( j < 0 ) {\n\t\t\t// Prepended singleton dimension; stride is zero...\n\t\t\tcontinue;\n\t\t}\n\t\td = sh[ j ];\n\t\tdim = shape[ i ];\n\t\tif ( dim !== 0 && dim < d ) {\n\t\t\tthrow new Error( format( 'invalid argument. Input array cannot be broadcast to the specified shape, as the specified shape has a dimension whose size is less than the size of the corresponding dimension in the input array. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t\tif ( d === dim ) {\n\t\t\tstrides[ i ] = st[ j ];\n\t\t} else if ( d === 1 ) {\n\t\t\t// In order to broadcast dimensions, we set the stride for that dimension to zero...\n\t\t\tstrides[ i ] = 0;\n\t\t} else {\n\t\t\t// At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when \"tiling\" an array; e.g., `dim=4` and `d=2`)...\n\t\t\tthrow new Error( format( 'invalid argument. Input array and the specified shape are broadcast incompatible. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t}\n\treturn ndarray( getDType( arr ), getData( arr ), copy( shape ), strides, getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nmodule.exports = broadcastArray;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast an ndarray to a specified shape.\n*\n* @module @stdlib/ndarray-base-broadcast-array\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var broadcastArray = require( '@stdlib/ndarray-base-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 = broadcastArray( 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,EAAO,QAAS,iCAAkC,EAClDC,EAAU,QAAS,2BAA4B,EAC/CC,EAAW,QAAS,4BAA6B,EACjDC,EAAa,QAAS,8BAA+B,EACrDC,EAAY,QAAS,6BAA8B,EACnDC,EAAW,QAAS,4BAA6B,EACjDC,EAAW,QAAS,4BAA6B,EACjDC,EAAU,QAAS,kCAAmC,EACtDC,EAAS,QAAS,uBAAwB,EA6D9C,SAASC,EAAgBC,EAAKC,EAAQ,CACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACA,EACAC,EACAC,EAKJ,GAHAH,EAAIL,EAAM,OACVG,EAAKZ,EAAUQ,EAAK,EAAM,EAC1BO,EAAIH,EAAG,OACFE,EAAIC,EACR,MAAM,IAAI,MAAO,8JAA+J,EAIjL,IADAL,EAAU,CAAC,EACLM,EAAI,EAAGA,EAAIF,EAAGE,IACnBN,EAAQ,KAAM,CAAE,EAIjB,IADAG,EAAKZ,EAAYO,EAAK,EAAM,EACtBQ,EAAIF,EAAE,EAAGE,GAAK,EAAGA,IAEtB,GADAC,EAAIF,EAAID,EAAIE,EACP,EAAAC,EAAI,GAMT,IAFA,EAAIL,EAAIK,CAAE,EACVN,EAAMF,EAAOO,CAAE,EACVL,IAAQ,GAAKA,EAAM,EACvB,MAAM,IAAI,MAAOL,EAAQ,8PAA+PR,EAAMc,CAAG,EAAE,KAAM,IAAK,EAAGd,EAAMW,CAAM,EAAE,KAAM,IAAK,EAAGO,CAAE,CAAE,EAElV,GAAK,IAAML,EACVD,EAASM,CAAE,EAAIH,EAAII,CAAE,UACV,IAAM,EAEjBP,EAASM,CAAE,EAAI,MAGf,OAAM,IAAI,MAAOV,EAAQ,2IAA4IR,EAAMc,CAAG,EAAE,KAAM,IAAK,EAAGd,EAAMW,CAAM,EAAE,KAAM,IAAK,EAAGO,CAAE,CAAE,EAGhO,OAAOjB,EAASK,EAAUI,CAAI,EAAGH,EAASG,CAAI,EAAGV,EAAMW,CAAM,EAAGC,EAASR,EAAWM,CAAI,EAAGL,EAAUK,CAAI,CAAE,CAC5G,CAKAX,EAAO,QAAUU,IChFjB,IAAIW,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "copy", "ndarray", "getShape", "getStrides", "getOffset", "getOrder", "getDType", "getData", "format", "broadcastArray", "arr", "shape", "strides", "dim", "sh", "st", "N", "M", "i", "j", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index db0f44c..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,65 +0,0 @@ - -{{alias}}( arr, shape ) - Broadcasts an ndarray to a specified shape. - - The 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. - - The returned array is a "base" ndarray, and, thus, the returned array 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. - - The function always returns a new ndarray instance even if the input ndarray - shape and the desired shape are the same. - - 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 13dcd66..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,94 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 broadcastArray = 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(); - - broadcastArray( x, [ 2, 2, 2 ] ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is not provided a first argument which is an ndarray... -{ - broadcastArray( '5', [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( 5, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( true, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( false, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( null, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( {}, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( [ '5' ], [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( ( 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(); - - broadcastArray( x, '5' ); // $ExpectError - broadcastArray( x, 5 ); // $ExpectError - broadcastArray( x, true ); // $ExpectError - broadcastArray( x, false ); // $ExpectError - broadcastArray( x, null ); // $ExpectError - broadcastArray( x, {} ); // $ExpectError - broadcastArray( x, [ '5' ] ); // $ExpectError - broadcastArray( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - - broadcastArray(); // $ExpectError - broadcastArray( x ); // $ExpectError - broadcastArray( x, [ 1, 2, 3 ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index f0dc7b6..0000000 --- a/examples/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 broadcastArray = require( './../lib' ); - -// Create a 2x2 array: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -// returns - -// Broadcast the array to 3x2x2: -var y = broadcastArray( 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 sub; -var v; -var i; -for ( i = 0; i < N; i++ ) { - v = y.iget( i ); - sub = ind2sub( sh, i ); - console.log( 'Y[%s] = %d', sub.join( ', ' ), v ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index 672e358..89664bc 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..9a4d472 --- /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 s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy-indexed@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function j(j,a){var h,p,f,l,v,b,c,g,x;if((v=a.length)<(b=(f=e(j,!1)).length))throw new Error(m("0i50Z"));for(h=[],g=0;g=0;g--)if(!((x=b-v+g)<0)){if(c=f[x],0!==(p=a[g])&&p\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction broadcastArray( arr, shape ) {\n\tvar strides;\n\tvar dim;\n\tvar sh;\n\tvar st;\n\tvar N;\n\tvar M;\n\tvar d;\n\tvar i;\n\tvar j;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\tM = sh.length;\n\tif ( N < M ) {\n\t\tthrow new Error( format('0i50Z') );\n\t}\n\t// Initialize a strides array...\n\tstrides = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tstrides.push( 0 );\n\t}\n\t// Determine the output array strides...\n\tst = getStrides( arr, false );\n\tfor ( i = N-1; i >= 0; i-- ) {\n\t\tj = M - N + i;\n\t\tif ( j < 0 ) {\n\t\t\t// Prepended singleton dimension; stride is zero...\n\t\t\tcontinue;\n\t\t}\n\t\td = sh[ j ];\n\t\tdim = shape[ i ];\n\t\tif ( dim !== 0 && dim < d ) {\n\t\t\tthrow new Error( format( '0i55F', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t\tif ( d === dim ) {\n\t\t\tstrides[ i ] = st[ j ];\n\t\t} else if ( d === 1 ) {\n\t\t\t// In order to broadcast dimensions, we set the stride for that dimension to zero...\n\t\t\tstrides[ i ] = 0;\n\t\t} else {\n\t\t\t// At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when \"tiling\" an array; e.g., `dim=4` and `d=2`)...\n\t\t\tthrow new Error( format( '0i55G', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t}\n\treturn ndarray( getDType( arr ), getData( arr ), copy( shape ), strides, getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nexport default broadcastArray;\n"],"names":["broadcastArray","arr","shape","strides","dim","sh","st","N","M","d","i","j","length","getShape","Error","format","push","getStrides","copy","join","ndarray","getDType","getData","getOffset","getOrder"],"mappings":";;s1BA2FA,SAASA,EAAgBC,EAAKC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAJ,EAAIL,EAAMU,SAEVJ,GADAH,EAAKQ,EAAUZ,GAAK,IACbW,QAEN,MAAM,IAAIE,MAAOC,EAAO,UAIzB,IADAZ,EAAU,GACJO,EAAI,EAAGA,EAAIH,EAAGG,IACnBP,EAAQa,KAAM,GAIf,IADAV,EAAKW,EAAYhB,GAAK,GAChBS,EAAIH,EAAE,EAAGG,GAAK,EAAGA,IAEtB,MADAC,EAAIH,EAAID,EAAIG,GACH,GAAT,CAMA,GAFAD,EAAIJ,EAAIM,GAEK,KADbP,EAAMF,EAAOQ,KACKN,EAAMK,EACvB,MAAM,IAAIK,MAAOC,EAAQ,QAASG,EAAMb,GAAKc,KAAM,MAAQD,EAAMhB,GAAQiB,KAAM,MAAQT,IAExF,GAAKD,IAAML,EACVD,EAASO,GAAMJ,EAAIK,OACb,IAAW,IAANF,EAKX,MAAM,IAAIK,MAAOC,EAAQ,QAASG,EAAMb,GAAKc,KAAM,MAAQD,EAAMhB,GAAQiB,KAAM,MAAQT,IAHvFP,EAASO,GAAM,CAIf,CAdA,CAgBF,OAAOU,EAASC,EAAUpB,GAAOqB,EAASrB,GAAOiB,EAAMhB,GAASC,EAASoB,EAAWtB,GAAOuB,EAAUvB,GACtG"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index b6aaa86..0000000 --- a/lib/index.js +++ /dev/null @@ -1,68 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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. -* -* @module @stdlib/ndarray-base-broadcast-array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var broadcastArray = require( '@stdlib/ndarray-base-broadcast-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = broadcastArray( 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 8496a36..0000000 --- a/lib/main.js +++ /dev/null @@ -1,143 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var copy = require( '@stdlib/array-base-copy-indexed' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require( '@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Broadcasts an ndarray to a specified shape. -* -* ## Notes -* -* - The 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. -* -* @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 = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] ); -* // throws -*/ -function broadcastArray( arr, shape ) { - var strides; - var dim; - var sh; - var st; - var N; - var M; - var d; - var i; - var j; - - N = shape.length; - sh = getShape( arr, false ); - M = sh.length; - if ( N < M ) { - throw new Error( format('0i50Z') ); - } - // Initialize a strides array... - strides = []; - for ( i = 0; i < N; i++ ) { - strides.push( 0 ); - } - // Determine the output array strides... - st = getStrides( arr, false ); - for ( i = N-1; i >= 0; i-- ) { - j = M - N + i; - if ( j < 0 ) { - // Prepended singleton dimension; stride is zero... - continue; - } - d = sh[ j ]; - dim = shape[ i ]; - if ( dim !== 0 && dim < d ) { - throw new Error( format( '0i55F', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); - } - if ( d === dim ) { - strides[ i ] = st[ j ]; - } else if ( d === 1 ) { - // In order to broadcast dimensions, we set the stride for that dimension to zero... - strides[ i ] = 0; - } else { - // At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when "tiling" an array; e.g., `dim=4` and `d=2`)... - throw new Error( format( '0i55G', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); - } - } - return ndarray( getDType( arr ), getData( arr ), copy( shape ), strides, getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len -} - - -// EXPORTS // - -module.exports = broadcastArray; diff --git a/package.json b/package.json index 26b0d41..5c882e8 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Broadcast an ndarray to a specified 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,46 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-copy-indexed": "^0.2.2", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/ndarray-base-data-buffer": "^0.2.2", - "@stdlib/ndarray-base-dtype": "^0.2.2", - "@stdlib/ndarray-base-offset": "^0.2.2", - "@stdlib/ndarray-base-order": "^0.2.2", - "@stdlib/ndarray-base-shape": "^0.2.2", - "@stdlib/ndarray-base-strides": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/ndarray-array": "^0.2.1", - "@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", @@ -92,7 +29,6 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..315fe2e --- /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 97decdb..0000000 --- a/test/test.js +++ /dev/null @@ -1,511 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 broadcastArray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastArray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a desired shape which has fewer dimensions than 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() { - broadcastArray( 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() { - broadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape and an input array shape 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() { - broadcastArray( x, value ); - }; - } -}); - -tape( 'the function returns a "base" ndarray instance', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = broadcastArray( 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 = broadcastArray( 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.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, 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 = broadcastArray( x, expected ); - - actual = y.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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 9cd450e02d12841c8fb780ce3676c819ecbd6158 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 19 May 2025 02:18:46 +0000 Subject: [PATCH 89/91] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index b4882c3..8496a36 100644 --- a/lib/main.js +++ b/lib/main.js @@ -28,7 +28,7 @@ var getOffset = require( '@stdlib/ndarray-base-offset' ); var getOrder = require( '@stdlib/ndarray-base-order' ); var getDType = require( '@stdlib/ndarray-base-dtype' ); var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -104,7 +104,7 @@ function broadcastArray( arr, shape ) { sh = getShape( arr, false ); M = sh.length; if ( N < M ) { - throw new Error( 'invalid argument. Cannot broadcast an array to a shape having fewer dimensions. Arrays can only be broadcasted to shapes having the same or more dimensions.' ); + throw new Error( format('0i50Z') ); } // Initialize a strides array... strides = []; @@ -122,7 +122,7 @@ function broadcastArray( arr, shape ) { d = sh[ j ]; dim = shape[ i ]; if ( dim !== 0 && dim < d ) { - throw new Error( format( 'invalid argument. Input array cannot be broadcast to the specified shape, as the specified shape has a dimension whose size is less than the size of the corresponding dimension in the input array. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); + throw new Error( format( '0i55F', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); } if ( d === dim ) { strides[ i ] = st[ j ]; @@ -131,7 +131,7 @@ function broadcastArray( arr, shape ) { strides[ i ] = 0; } else { // At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when "tiling" an array; e.g., `dim=4` and `d=2`)... - throw new Error( format( 'invalid argument. Input array and the specified shape are broadcast incompatible. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); + throw new Error( format( '0i55G', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); } } return ndarray( getDType( arr ), getData( arr ), copy( shape ), strides, getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len diff --git a/package.json b/package.json index 85dd6c0..26b0d41 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "@stdlib/ndarray-base-order": "^0.2.2", "@stdlib/ndarray-base-shape": "^0.2.2", "@stdlib/ndarray-base-strides": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.3", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, From 4a132b225acf44d49cfe4abf475d644549d2911b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 19 May 2025 02:39:20 +0000 Subject: [PATCH 90/91] Remove files --- index.d.ts | 80 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4927 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 89664bc..0000000 --- a/index.d.ts +++ /dev/null @@ -1,80 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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. -* -* ## Notes -* -* - The function throws an error if a provided ndarray is incompatible with a provided shape. -* - The 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. -* - The returned array is a "base" ndarray, and, thus, the returned array 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 always returns a new ndarray instance even if the input ndarray shape and the desired shape are the same. -* -* @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 -* @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 = broadcastArray( 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 broadcastArray( arr: ndarray, shape: ArrayLike ): ndarray; - - -// EXPORTS // - -export = broadcastArray; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 9a4d472..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 s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy-indexed@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function j(j,a){var h,p,f,l,v,b,c,g,x;if((v=a.length)<(b=(f=e(j,!1)).length))throw new Error(m("0i50Z"));for(h=[],g=0;g=0;g--)if(!((x=b-v+g)<0)){if(c=f[x],0!==(p=a[g])&&p\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction broadcastArray( arr, shape ) {\n\tvar strides;\n\tvar dim;\n\tvar sh;\n\tvar st;\n\tvar N;\n\tvar M;\n\tvar d;\n\tvar i;\n\tvar j;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\tM = sh.length;\n\tif ( N < M ) {\n\t\tthrow new Error( format('0i50Z') );\n\t}\n\t// Initialize a strides array...\n\tstrides = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tstrides.push( 0 );\n\t}\n\t// Determine the output array strides...\n\tst = getStrides( arr, false );\n\tfor ( i = N-1; i >= 0; i-- ) {\n\t\tj = M - N + i;\n\t\tif ( j < 0 ) {\n\t\t\t// Prepended singleton dimension; stride is zero...\n\t\t\tcontinue;\n\t\t}\n\t\td = sh[ j ];\n\t\tdim = shape[ i ];\n\t\tif ( dim !== 0 && dim < d ) {\n\t\t\tthrow new Error( format( '0i55F', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t\tif ( d === dim ) {\n\t\t\tstrides[ i ] = st[ j ];\n\t\t} else if ( d === 1 ) {\n\t\t\t// In order to broadcast dimensions, we set the stride for that dimension to zero...\n\t\t\tstrides[ i ] = 0;\n\t\t} else {\n\t\t\t// At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when \"tiling\" an array; e.g., `dim=4` and `d=2`)...\n\t\t\tthrow new Error( format( '0i55G', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t}\n\treturn ndarray( getDType( arr ), getData( arr ), copy( shape ), strides, getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nexport default broadcastArray;\n"],"names":["broadcastArray","arr","shape","strides","dim","sh","st","N","M","d","i","j","length","getShape","Error","format","push","getStrides","copy","join","ndarray","getDType","getData","getOffset","getOrder"],"mappings":";;s1BA2FA,SAASA,EAAgBC,EAAKC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAJ,EAAIL,EAAMU,SAEVJ,GADAH,EAAKQ,EAAUZ,GAAK,IACbW,QAEN,MAAM,IAAIE,MAAOC,EAAO,UAIzB,IADAZ,EAAU,GACJO,EAAI,EAAGA,EAAIH,EAAGG,IACnBP,EAAQa,KAAM,GAIf,IADAV,EAAKW,EAAYhB,GAAK,GAChBS,EAAIH,EAAE,EAAGG,GAAK,EAAGA,IAEtB,MADAC,EAAIH,EAAID,EAAIG,GACH,GAAT,CAMA,GAFAD,EAAIJ,EAAIM,GAEK,KADbP,EAAMF,EAAOQ,KACKN,EAAMK,EACvB,MAAM,IAAIK,MAAOC,EAAQ,QAASG,EAAMb,GAAKc,KAAM,MAAQD,EAAMhB,GAAQiB,KAAM,MAAQT,IAExF,GAAKD,IAAML,EACVD,EAASO,GAAMJ,EAAIK,OACb,IAAW,IAANF,EAKX,MAAM,IAAIK,MAAOC,EAAQ,QAASG,EAAMb,GAAKc,KAAM,MAAQD,EAAMhB,GAAQiB,KAAM,MAAQT,IAHvFP,EAASO,GAAM,CAIf,CAdA,CAgBF,OAAOU,EAASC,EAAUpB,GAAOqB,EAASrB,GAAOiB,EAAMhB,GAASC,EAASoB,EAAWtB,GAAOuB,EAAUvB,GACtG"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 315fe2e..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From b4c93ac7339cba47c285171ea5c50983f2abb3b3 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 19 May 2025 02:39:51 +0000 Subject: [PATCH 91/91] Auto-generated commit --- .editorconfig | 180 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 194 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 213 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 49 +- SECURITY.md | 5 - benchmark/benchmark.js | 161 - benchmark/benchmark.ndims.js | 110 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 65 - docs/types/test.ts | 94 - examples/index.js | 49 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 68 - lib/main.js | 143 - package.json | 68 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 511 -- 45 files changed, 4870 insertions(+), 4917 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 (96%) 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 aee823f..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2025-05-19T02:00:11.303Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 9b42339..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-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 7ab66d5..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-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 e1434bb..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: '28 4 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -177,7 +168,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]. @@ -240,11 +231,11 @@ Copyright © 2016-2025. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-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 d0243ca..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,161 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 broadcastArray = 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 = broadcastArray( 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', 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 = broadcastArray( 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', 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 = broadcastArray( 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(); -}); diff --git a/benchmark/benchmark.ndims.js b/benchmark/benchmark.ndims.js deleted file mode 100644 index 9530251..0000000 --- a/benchmark/benchmark.ndims.js +++ /dev/null @@ -1,110 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 broadcastArray = 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 = broadcastArray( 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 f51adca..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-array" -%% click B href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-array -[production-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-array/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-array/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-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 a9d3107..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import broadcastArray from '../docs/types/index'; -export = broadcastArray; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 4f8387b..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var m=function(a,r){return function(){return r||a((r={exports:{}}).exports,r),r.exports}};var c=m(function(x,f){"use strict";var t=require("@stdlib/array-base-copy-indexed"),g=require("@stdlib/ndarray-base-ctor"),l=require("@stdlib/ndarray-base-shape"),y=require("@stdlib/ndarray-base-strides"),q=require("@stdlib/ndarray-base-offset"),b=require("@stdlib/ndarray-base-order"),w=require("@stdlib/ndarray-base-dtype"),D=require("@stdlib/ndarray-base-data-buffer"),p=require("@stdlib/string-format");function j(a,r){var i,o,s,v,n,u,d,e,h;if(n=r.length,s=l(a,!1),u=s.length,n=0;e--)if(h=u-n+e,!(h<0)){if(d=s[h],o=r[e],o!==0&&o\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction broadcastArray( arr, shape ) {\n\tvar strides;\n\tvar dim;\n\tvar sh;\n\tvar st;\n\tvar N;\n\tvar M;\n\tvar d;\n\tvar i;\n\tvar j;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\tM = sh.length;\n\tif ( N < M ) {\n\t\tthrow new Error( 'invalid argument. Cannot broadcast an array to a shape having fewer dimensions. Arrays can only be broadcasted to shapes having the same or more dimensions.' );\n\t}\n\t// Initialize a strides array...\n\tstrides = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tstrides.push( 0 );\n\t}\n\t// Determine the output array strides...\n\tst = getStrides( arr, false );\n\tfor ( i = N-1; i >= 0; i-- ) {\n\t\tj = M - N + i;\n\t\tif ( j < 0 ) {\n\t\t\t// Prepended singleton dimension; stride is zero...\n\t\t\tcontinue;\n\t\t}\n\t\td = sh[ j ];\n\t\tdim = shape[ i ];\n\t\tif ( dim !== 0 && dim < d ) {\n\t\t\tthrow new Error( format( 'invalid argument. Input array cannot be broadcast to the specified shape, as the specified shape has a dimension whose size is less than the size of the corresponding dimension in the input array. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t\tif ( d === dim ) {\n\t\t\tstrides[ i ] = st[ j ];\n\t\t} else if ( d === 1 ) {\n\t\t\t// In order to broadcast dimensions, we set the stride for that dimension to zero...\n\t\t\tstrides[ i ] = 0;\n\t\t} else {\n\t\t\t// At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when \"tiling\" an array; e.g., `dim=4` and `d=2`)...\n\t\t\tthrow new Error( format( 'invalid argument. Input array and the specified shape are broadcast incompatible. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t}\n\treturn ndarray( getDType( arr ), getData( arr ), copy( shape ), strides, getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nmodule.exports = broadcastArray;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Broadcast an ndarray to a specified shape.\n*\n* @module @stdlib/ndarray-base-broadcast-array\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var broadcastArray = require( '@stdlib/ndarray-base-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 = broadcastArray( 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,EAAO,QAAS,iCAAkC,EAClDC,EAAU,QAAS,2BAA4B,EAC/CC,EAAW,QAAS,4BAA6B,EACjDC,EAAa,QAAS,8BAA+B,EACrDC,EAAY,QAAS,6BAA8B,EACnDC,EAAW,QAAS,4BAA6B,EACjDC,EAAW,QAAS,4BAA6B,EACjDC,EAAU,QAAS,kCAAmC,EACtDC,EAAS,QAAS,uBAAwB,EA6D9C,SAASC,EAAgBC,EAAKC,EAAQ,CACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACA,EACAC,EACAC,EAKJ,GAHAH,EAAIL,EAAM,OACVG,EAAKZ,EAAUQ,EAAK,EAAM,EAC1BO,EAAIH,EAAG,OACFE,EAAIC,EACR,MAAM,IAAI,MAAO,8JAA+J,EAIjL,IADAL,EAAU,CAAC,EACLM,EAAI,EAAGA,EAAIF,EAAGE,IACnBN,EAAQ,KAAM,CAAE,EAIjB,IADAG,EAAKZ,EAAYO,EAAK,EAAM,EACtBQ,EAAIF,EAAE,EAAGE,GAAK,EAAGA,IAEtB,GADAC,EAAIF,EAAID,EAAIE,EACP,EAAAC,EAAI,GAMT,IAFA,EAAIL,EAAIK,CAAE,EACVN,EAAMF,EAAOO,CAAE,EACVL,IAAQ,GAAKA,EAAM,EACvB,MAAM,IAAI,MAAOL,EAAQ,8PAA+PR,EAAMc,CAAG,EAAE,KAAM,IAAK,EAAGd,EAAMW,CAAM,EAAE,KAAM,IAAK,EAAGO,CAAE,CAAE,EAElV,GAAK,IAAML,EACVD,EAASM,CAAE,EAAIH,EAAII,CAAE,UACV,IAAM,EAEjBP,EAASM,CAAE,EAAI,MAGf,OAAM,IAAI,MAAOV,EAAQ,2IAA4IR,EAAMc,CAAG,EAAE,KAAM,IAAK,EAAGd,EAAMW,CAAM,EAAE,KAAM,IAAK,EAAGO,CAAE,CAAE,EAGhO,OAAOjB,EAASK,EAAUI,CAAI,EAAGH,EAASG,CAAI,EAAGV,EAAMW,CAAM,EAAGC,EAASR,EAAWM,CAAI,EAAGL,EAAUK,CAAI,CAAE,CAC5G,CAKAX,EAAO,QAAUU,IChFjB,IAAIW,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "copy", "ndarray", "getShape", "getStrides", "getOffset", "getOrder", "getDType", "getData", "format", "broadcastArray", "arr", "shape", "strides", "dim", "sh", "st", "N", "M", "i", "j", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index db0f44c..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,65 +0,0 @@ - -{{alias}}( arr, shape ) - Broadcasts an ndarray to a specified shape. - - The 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. - - The returned array is a "base" ndarray, and, thus, the returned array 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. - - The function always returns a new ndarray instance even if the input ndarray - shape and the desired shape are the same. - - 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 13dcd66..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,94 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 broadcastArray = 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(); - - broadcastArray( x, [ 2, 2, 2 ] ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is not provided a first argument which is an ndarray... -{ - broadcastArray( '5', [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( 5, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( true, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( false, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( null, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( {}, [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( [ '5' ], [ 2, 2, 2 ] ); // $ExpectError - broadcastArray( ( 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(); - - broadcastArray( x, '5' ); // $ExpectError - broadcastArray( x, 5 ); // $ExpectError - broadcastArray( x, true ); // $ExpectError - broadcastArray( x, false ); // $ExpectError - broadcastArray( x, null ); // $ExpectError - broadcastArray( x, {} ); // $ExpectError - broadcastArray( x, [ '5' ] ); // $ExpectError - broadcastArray( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = array(); - - broadcastArray(); // $ExpectError - broadcastArray( x ); // $ExpectError - broadcastArray( x, [ 1, 2, 3 ], [ 2, 3 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index f0dc7b6..0000000 --- a/examples/index.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 broadcastArray = require( './../lib' ); - -// Create a 2x2 array: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -// returns - -// Broadcast the array to 3x2x2: -var y = broadcastArray( 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 sub; -var v; -var i; -for ( i = 0; i < N; i++ ) { - v = y.iget( i ); - sub = ind2sub( sh, i ); - console.log( 'Y[%s] = %d', sub.join( ', ' ), v ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index 672e358..89664bc 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..9a4d472 --- /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 s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy-indexed@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function j(j,a){var h,p,f,l,v,b,c,g,x;if((v=a.length)<(b=(f=e(j,!1)).length))throw new Error(m("0i50Z"));for(h=[],g=0;g=0;g--)if(!((x=b-v+g)<0)){if(c=f[x],0!==(p=a[g])&&p\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] );\n* // throws \n*/\nfunction broadcastArray( arr, shape ) {\n\tvar strides;\n\tvar dim;\n\tvar sh;\n\tvar st;\n\tvar N;\n\tvar M;\n\tvar d;\n\tvar i;\n\tvar j;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\tM = sh.length;\n\tif ( N < M ) {\n\t\tthrow new Error( format('0i50Z') );\n\t}\n\t// Initialize a strides array...\n\tstrides = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tstrides.push( 0 );\n\t}\n\t// Determine the output array strides...\n\tst = getStrides( arr, false );\n\tfor ( i = N-1; i >= 0; i-- ) {\n\t\tj = M - N + i;\n\t\tif ( j < 0 ) {\n\t\t\t// Prepended singleton dimension; stride is zero...\n\t\t\tcontinue;\n\t\t}\n\t\td = sh[ j ];\n\t\tdim = shape[ i ];\n\t\tif ( dim !== 0 && dim < d ) {\n\t\t\tthrow new Error( format( '0i55F', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t\tif ( d === dim ) {\n\t\t\tstrides[ i ] = st[ j ];\n\t\t} else if ( d === 1 ) {\n\t\t\t// In order to broadcast dimensions, we set the stride for that dimension to zero...\n\t\t\tstrides[ i ] = 0;\n\t\t} else {\n\t\t\t// At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when \"tiling\" an array; e.g., `dim=4` and `d=2`)...\n\t\t\tthrow new Error( format( '0i55G', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t}\n\treturn ndarray( getDType( arr ), getData( arr ), copy( shape ), strides, getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nexport default broadcastArray;\n"],"names":["broadcastArray","arr","shape","strides","dim","sh","st","N","M","d","i","j","length","getShape","Error","format","push","getStrides","copy","join","ndarray","getDType","getData","getOffset","getOrder"],"mappings":";;s1BA2FA,SAASA,EAAgBC,EAAKC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,IAHAJ,EAAIL,EAAMU,SAEVJ,GADAH,EAAKQ,EAAUZ,GAAK,IACbW,QAEN,MAAM,IAAIE,MAAOC,EAAO,UAIzB,IADAZ,EAAU,GACJO,EAAI,EAAGA,EAAIH,EAAGG,IACnBP,EAAQa,KAAM,GAIf,IADAV,EAAKW,EAAYhB,GAAK,GAChBS,EAAIH,EAAE,EAAGG,GAAK,EAAGA,IAEtB,MADAC,EAAIH,EAAID,EAAIG,GACH,GAAT,CAMA,GAFAD,EAAIJ,EAAIM,GAEK,KADbP,EAAMF,EAAOQ,KACKN,EAAMK,EACvB,MAAM,IAAIK,MAAOC,EAAQ,QAASG,EAAMb,GAAKc,KAAM,MAAQD,EAAMhB,GAAQiB,KAAM,MAAQT,IAExF,GAAKD,IAAML,EACVD,EAASO,GAAMJ,EAAIK,OACb,IAAW,IAANF,EAKX,MAAM,IAAIK,MAAOC,EAAQ,QAASG,EAAMb,GAAKc,KAAM,MAAQD,EAAMhB,GAAQiB,KAAM,MAAQT,IAHvFP,EAASO,GAAM,CAIf,CAdA,CAgBF,OAAOU,EAASC,EAAUpB,GAAOqB,EAASrB,GAAOiB,EAAMhB,GAASC,EAASoB,EAAWtB,GAAOuB,EAAUvB,GACtG"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index b6aaa86..0000000 --- a/lib/index.js +++ /dev/null @@ -1,68 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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. -* -* @module @stdlib/ndarray-base-broadcast-array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var broadcastArray = require( '@stdlib/ndarray-base-broadcast-array' ); -* -* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var shx = x.shape; -* // returns [ 2, 2 ] -* -* var y = broadcastArray( 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 8496a36..0000000 --- a/lib/main.js +++ /dev/null @@ -1,143 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var copy = require( '@stdlib/array-base-copy-indexed' ); -var ndarray = require( '@stdlib/ndarray-base-ctor' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require( '@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Broadcasts an ndarray to a specified shape. -* -* ## Notes -* -* - The 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. -* -* @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 = broadcastArray( 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 = broadcastArray( x, [ 3, 2 ] ); -* // throws -*/ -function broadcastArray( arr, shape ) { - var strides; - var dim; - var sh; - var st; - var N; - var M; - var d; - var i; - var j; - - N = shape.length; - sh = getShape( arr, false ); - M = sh.length; - if ( N < M ) { - throw new Error( format('0i50Z') ); - } - // Initialize a strides array... - strides = []; - for ( i = 0; i < N; i++ ) { - strides.push( 0 ); - } - // Determine the output array strides... - st = getStrides( arr, false ); - for ( i = N-1; i >= 0; i-- ) { - j = M - N + i; - if ( j < 0 ) { - // Prepended singleton dimension; stride is zero... - continue; - } - d = sh[ j ]; - dim = shape[ i ]; - if ( dim !== 0 && dim < d ) { - throw new Error( format( '0i55F', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); - } - if ( d === dim ) { - strides[ i ] = st[ j ]; - } else if ( d === 1 ) { - // In order to broadcast dimensions, we set the stride for that dimension to zero... - strides[ i ] = 0; - } else { - // At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when "tiling" an array; e.g., `dim=4` and `d=2`)... - throw new Error( format( '0i55G', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) ); - } - } - return ndarray( getDType( arr ), getData( arr ), copy( shape ), strides, getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len -} - - -// EXPORTS // - -module.exports = broadcastArray; diff --git a/package.json b/package.json index 26b0d41..5c882e8 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Broadcast an ndarray to a specified 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,46 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-copy-indexed": "^0.2.2", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/ndarray-base-data-buffer": "^0.2.2", - "@stdlib/ndarray-base-dtype": "^0.2.2", - "@stdlib/ndarray-base-offset": "^0.2.2", - "@stdlib/ndarray-base-order": "^0.2.2", - "@stdlib/ndarray-base-shape": "^0.2.2", - "@stdlib/ndarray-base-strides": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/ndarray-array": "^0.2.1", - "@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", @@ -92,7 +29,6 @@ "utils", "util" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..315fe2e --- /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 97decdb..0000000 --- a/test/test.js +++ /dev/null @@ -1,511 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 broadcastArray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof broadcastArray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a desired shape which has fewer dimensions than 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() { - broadcastArray( 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() { - broadcastArray( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided a desired shape and an input array shape 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() { - broadcastArray( x, value ); - }; - } -}); - -tape( 'the function returns a "base" ndarray instance', function test( t ) { - var x; - var y; - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = broadcastArray( 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 = broadcastArray( 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.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, 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 = broadcastArray( x, expected ); - - actual = y.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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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 = broadcastArray( x, expected ); - - actual = y.shape; - 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(); -});